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

МГТУ

Anton Davydov
December 10, 2019
49

 МГТУ

Anton Davydov

December 10, 2019
Tweet

Transcript

  1. • Memes • Coffee • Beer • Kendo • Psychology

    • jRPG • SW-2039-0208-4228 / 3DS also welcome • How to draw images for presentations
  2. apps/ ├── admin │ ├── application.rb │ ├── assets │

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

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

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

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

    │ ├── entities │ │ └── user.rb │ ├── mailers │ │ └── templates │ └── repositories
  7. 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
  8. 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
  9. events - PubSub framework for Ruby cli - CLI framework

    for Ruby webconsole - Web console for development ujs - Assets management for Ruby
  10. # hanami-router class HelloApp def call(env) [200, { **env },

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

    private def user_params end end Controllers: 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. class User < ActiveRecord::Base include Gravtastic before_destroy :yank_gems has_many :rubygems,

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

    through: :ownerships validates :name, presence: true # ... end Model: Rails
  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. 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
  19. 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
  20. 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
  21. >> repo = UserRepository.new => #<UserRepository relations=[:users]> >> repo.find(1) =>

    #<User:0x007fa14d1a1fa8 @attributes={…}> >> repo.find_by_name(‘Anton’) => #<User:0x007fa14d1a1fa8 @attributes={…}> Model: hanami repository
  22. class Service attr_reader :repo def initialize(repo: UserRepo.new) @repo = repo

    end def call(payload) user = repo.find(payload[:id]) # … end end
  23. DDD

  24. Rails action test describe BoardController do let(:response){ get :index }

    it 'is successful' do expect(response).to eq(200) end end
  25. Action test describe Web::Controllers::Board::Index do let(:action){ Board::Index.new } let(:params){ Hash[]

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

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

    } it 'is successful' do response = action.call(params) expect(response[0]).to eq(200) end end
  28. TDD