Bob Firestone
1.ruby developer
2.the longer I develop the less code I try and
write
3.am I the only one that thinks whiskey wednesday
need to be mandatory?
twitter @bobfirestone
Ruby Web Dev from
10,000 feet
rack > micro frameworks > frameworks
micro frameworks
• Sinatra
• Padrino
• NYNY
• Cuba
frameworks
• Ruby on Rails
what else is there?
hanami
(formerly lotus)
rails is great
except when it isn't
rails is still
king when you need
to quickly
prototype things
rails is still fantastic and
realistically enough to build
about 95% of what makes up
the internet1
1
with appropriate caching strategy and well written code
where hanami
excels is off of
the rails happy
path
if you start talking about using rails engines
to make your code modular take a look at hanami
what is hanami
• ruby web framework
• lighter weight (performance closer to sinatra)
• mvc
• opinionated (just different opinions than
rails)
• ORM agnostic... but comes with hanami models
out of the box
• has generators for boilerplate stuff
<fake> live coding time
$ hanami new ruby_rocks
$ cd ruby_rocks
$ bundle
file structure
$ tree -L 1
├── Gemfile
├── Rakefile
├── apps
├── config
├── config.ru
├── db
├── lib
├── public
└── spec
that apps directory
├── apps
│ └── web
│ ├── application.rb
│ ├── assets
│ ├── config
│ ├── controllers
│ ├── templates
│ └── views
lib ftw
├── lib
│ ├── rubyrocks
│ │ ├── entities
│ │ ├── mailers
│ │ └── repositories
│ └── rubyrocks.rb
1st Page
bundle exec hanami generate action web home#index
create spec/web/controllers/home/index_spec.rb
create apps/web/controllers/home/index.rb
create apps/web/views/home/index.rb
create apps/web/templates/home/index.html.erb
create spec/web/views/home/index_spec.rb
insert apps/web/config/routes.rb
views vs templates
• hanami template = rails view
• hanami view = decorator
bob???
that was boring!!!
show us how the
plural apps
works!?!?2
2
yes I do troll my own presentations
creating a new app
bundle exec hanami generate app api
create apps/api/application.rb
create apps/api/config/routes.rb
create apps/api/views/application_layout.rb
create apps/api/templates/application.html.erb
create apps/api/assets/favicon.ico
create apps/api/controllers/.gitkeep
create apps/api/assets/images/.gitkeep
create apps/api/assets/javascripts/.gitkeep
create apps/api/assets/stylesheets/.gitkeep
create spec/api/features/.gitkeep
create spec/api/controllers/.gitkeep
create spec/api/views/.gitkeep
insert config/environment.rb
insert config/environment.rb
append .env.development
append .env.test
new apps dir file tree
!"" apps
#   !"" api
#   #   !"" application.rb
#   #   !"" assets
#   #   !"" config
#   #   !"" controllers
#   #   !"" templates
#   #   $"" views
#   $"" web
#   !"" application.rb
#   !"" assets
#   !"" config
#   !"" controllers
#   !"" templates
#   $"" views
models
separates behavior from persistence
• entity (behavior)
• repositories (persistence)
generate a model & use it in
both apps
$ bundle exec hanami generate model post
create lib/ruby_rocks/entities/post.rb
create lib/ruby_rocks/repositories/post_repository.rb
create db/migrations/20170802213537_create_posts.rb
create spec/ruby_rocks/entities/post_spec.rb
create spec/ruby_rocks/repositories/post_repository_spec.rb
edit the migration file
Hanami::Model.migration do
change do
create_table :posts do
primary_key :id
column :title, String
column :body, String
column :created_at, DateTime, null: false
column :updated_at, DateTime, null: false
end
end
end
lets just look at
the code
next months topic
JavaScript
who wants to present?

Hanami

  • 1.
    Bob Firestone 1.ruby developer 2.thelonger I develop the less code I try and write 3.am I the only one that thinks whiskey wednesday need to be mandatory? twitter @bobfirestone
  • 2.
    Ruby Web Devfrom 10,000 feet rack > micro frameworks > frameworks
  • 3.
    micro frameworks • Sinatra •Padrino • NYNY • Cuba
  • 4.
    frameworks • Ruby onRails what else is there?
  • 5.
  • 6.
    rails is great exceptwhen it isn't
  • 7.
    rails is still kingwhen you need to quickly prototype things
  • 8.
    rails is stillfantastic and realistically enough to build about 95% of what makes up the internet1 1 with appropriate caching strategy and well written code
  • 9.
    where hanami excels isoff of the rails happy path if you start talking about using rails engines to make your code modular take a look at hanami
  • 10.
    what is hanami •ruby web framework • lighter weight (performance closer to sinatra) • mvc • opinionated (just different opinions than rails) • ORM agnostic... but comes with hanami models out of the box • has generators for boilerplate stuff
  • 11.
    <fake> live codingtime $ hanami new ruby_rocks $ cd ruby_rocks $ bundle
  • 12.
    file structure $ tree-L 1 ├── Gemfile ├── Rakefile ├── apps ├── config ├── config.ru ├── db ├── lib ├── public └── spec
  • 13.
    that apps directory ├──apps │ └── web │ ├── application.rb │ ├── assets │ ├── config │ ├── controllers │ ├── templates │ └── views
  • 14.
    lib ftw ├── lib │├── rubyrocks │ │ ├── entities │ │ ├── mailers │ │ └── repositories │ └── rubyrocks.rb
  • 15.
    1st Page bundle exechanami generate action web home#index create spec/web/controllers/home/index_spec.rb create apps/web/controllers/home/index.rb create apps/web/views/home/index.rb create apps/web/templates/home/index.html.erb create spec/web/views/home/index_spec.rb insert apps/web/config/routes.rb
  • 16.
    views vs templates •hanami template = rails view • hanami view = decorator
  • 17.
    bob??? that was boring!!! showus how the plural apps works!?!?2 2 yes I do troll my own presentations
  • 18.
    creating a newapp bundle exec hanami generate app api create apps/api/application.rb create apps/api/config/routes.rb create apps/api/views/application_layout.rb create apps/api/templates/application.html.erb create apps/api/assets/favicon.ico create apps/api/controllers/.gitkeep create apps/api/assets/images/.gitkeep create apps/api/assets/javascripts/.gitkeep create apps/api/assets/stylesheets/.gitkeep create spec/api/features/.gitkeep create spec/api/controllers/.gitkeep create spec/api/views/.gitkeep insert config/environment.rb insert config/environment.rb append .env.development append .env.test
  • 19.
    new apps dirfile tree !"" apps #   !"" api #   #   !"" application.rb #   #   !"" assets #   #   !"" config #   #   !"" controllers #   #   !"" templates #   #   $"" views #   $"" web #   !"" application.rb #   !"" assets #   !"" config #   !"" controllers #   !"" templates #   $"" views
  • 20.
    models separates behavior frompersistence • entity (behavior) • repositories (persistence)
  • 21.
    generate a model& use it in both apps $ bundle exec hanami generate model post create lib/ruby_rocks/entities/post.rb create lib/ruby_rocks/repositories/post_repository.rb create db/migrations/20170802213537_create_posts.rb create spec/ruby_rocks/entities/post_spec.rb create spec/ruby_rocks/repositories/post_repository_spec.rb
  • 22.
    edit the migrationfile Hanami::Model.migration do change do create_table :posts do primary_key :id column :title, String column :body, String column :created_at, DateTime, null: false column :updated_at, DateTime, null: false end end end
  • 23.
    lets just lookat the code
  • 24.