Upgrade to Pro — share decks privately, control downloads, hide ads and more …

viewing ruby blossom kaigi2017

Anton Davydov
September 18, 2017

viewing ruby blossom kaigi2017

Slides from my talk about hanami at rubykaigi2017

Links:
railshurts.com/quiz
awesome-hanami.org
www.ossboard.org
octostar.herokuapp.com
contributors.hanamirb.org
hanamirb.org
gitter.im/hanami/chat
discuss.hanamirb.org

Anton Davydov

September 18, 2017
Tweet

More Decks by Anton Davydov

Other Decks in Programming

Transcript

  1. apps/ ├── admin │ ├── application.rb │ ├── assets │

    │ └── ... │ ├── config │ │ └── ... │ ├── controllers │ │ └── ... │ ├── templates │ │ └── ... │ └── views │ └── ... └── web ├── ...
  2. lib/ ├── project_name │ ├── interactors │ │ └── create_user.rb

    │ ├── entities │ │ └── user.rb │ ├── mailers │ │ └── templates │ └── repositories │ └── user_repository.rb └── project_name.rb
  3. lib/ ├── project_name │ ├── interactors │ │ └── create_user.rb

    │ ├── entities │ │ └── user.rb │ ├── mailers │ │ └── templates │ └── repositories │ └── user_repository.rb └── project_name.rb
  4. lib/ ├── project_name │ ├── interactors │ │ └── create_user.rb

    │ ├── entities │ │ └── user.rb │ ├── mailers │ │ └── templates │ └── repositories │ └── user_repository.rb └── project_name.rb
  5. lib/ ├── project_name │ ├── interactors │ │ └── create_user.rb

    │ ├── entities │ │ └── user.rb │ ├── mailers │ │ └── templates │ └── repositories │ └── user_repository.rb └── project_name.rb
  6. hanami - Base repository, CLI router - Rack compatible HTTP

    router for Ruby controller - Full featured and fast actions for Rack utils - Ruby core extensions and class utilities model - Persistence with entities and repositories
  7. validations - Validations mixin for Ruby objects helpers - View

    helpers for Ruby applications view - Presentation with a separation assets - Assets management for Ruby mailer - Mail for Ruby applications
  8. # hanami-router class HelloApp def call(env) [200, { **env },

    ['Hello!']] end end router = Hanami::Router.new router.get '/', to: 'hello_app'
  9. class UsersController < AC def new end def send_sms end


    private def user_params end end Controllers: Rails
  10. class User < ActiveRecord::Base
 include Gravtastic before_destroy :yank_gems has_many :rubygems,

    through: :ownerships validates :name, presence: true # ... end Model: Rails
  11. class User < ActiveRecord::Base
 include Gravtastic before_destroy :yank_gems has_many :rubygems,

    through: :ownerships validates :name, presence: true # ... end Model: Rails
  12. class User < ActiveRecord::Base
 include Gravtastic before_destroy :yank_gems has_many :rubygems,

    through: :ownerships validates :name, presence: true # ... end Model: Rails
  13. class User < ActiveRecord::Base
 include Gravtastic before_destroy :yank_gems has_many :rubygems,

    through: :ownerships validates :name, presence: true # ... end Model: Rails
  14. class User < ActiveRecord::Base
 include Gravtastic before_destroy :yank_gems has_many :rubygems,

    through: :ownerships validates :name, presence: true # ... end Model: Rails
  15. Model: hanami entity >> user = User.new(id: 1) => #<User:0x007fa14d1e0528

    @attributes={:id=>1}> >> user.id => 1 >> user.id = 1 NoMethodError: undefined method `id=' for #<User:0x007fa14d1e0528 @attributes={:id=>1}> Did you mean? id
  16. Model: hanami entity >> user = User.new(id: 1) => #<User:0x007fa14d1e0528

    @attributes={:id=>1}> >> user.id => 1 >> user.id = 1 NoMethodError: undefined method `id=' for #<User:0x007fa14d1e0528 @attributes={:id=>1}> Did you mean? id
  17. Model: hanami entity >> user = User.new(id: 1) => #<User:0x007fa14d1e0528

    @attributes={:id=>1}> >> user.id => 1 >> user.id = 1 NoMethodError: undefined method `id=' for #<User:0x007fa14d1e0528 @attributes={:id=>1}> Did you mean? id
  18. class UserRepository < Hanami::Repository associations do has_many :books end def

    find_by_name(name) users # => ROM relation users.where(name: name).limit(1).order { id }.one end end Model: hanami repository
  19. >> repo = UserRepository.new => #<UserRepository relations=[:users]> >> repo.find(1) =>

    #<User:0x007fa14d1a1fa8 @attributes={…}> >> repo.find_by_name(‘Anton’) => #<User:0x007fa14d1a1fa8 @attributes={…}> Model: hanami repository
  20. Action test describe Web::Controllers::Board::Index do let(:action){ Board::Index.new } let(:params){ Hash[]

    } it 'is successful' do response = action.call(params) response[0].must_equal 200 end end
  21. Action test describe Web::Controllers::Board::Index do let(:action){ Board::Index.new } let(:params){ Hash[]

    } it 'is successful' do response = action.call(params) response[0].must_equal 200 end end
  22. Action test describe Web::Controllers::Board::Index do let(:action){ Board::Index.new } let(:params){ Hash[]

    } it 'is successful' do response = action.call(params) response[0].must_equal 200 end end
  23. TDD

  24. TDD