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

2024 - COSCUP - Clean Architecture in Rails

2024 - COSCUP - Clean Architecture in Rails

蒼時弦や

August 03, 2024
Tweet

More Decks by 蒼時弦や

Other Decks in Technology

Transcript

  1. class def end def = += end def = end

    def end end ; (amount ) @height amount (amount ); (slot); Desk work up down memory # Standing Desk # ... 1 1
  2. class def = end end
 class def = new
 end

    def = end
 end (amount ); @motor . (amount ) @motor.forward(amount) Motor
 forward Desk
 initialize up 1 Motor 1 # ... # ... # ...
  3. class def = end end
 (amount ); Motor
 forward 1

    # ... class Desk
 def initialize @motor = Motor.new
 end # ... def up(amount=1) @motor.forward(amount) end
 # ... end
  4. class < def end private def end def end end

    ; ; ; CheckoutController ApplicationController create calculate_discount calculate_amount # ...
  5. class end class end class < def end end ;

    DiscountService CheckoutService CheckoutController ApplicationController create # ...
  6. class def = end end
 class def = new
 end

    def = end
 end (amount ); @motor . (amount ) @motor.forward(amount) Motor
 forward Desk
 initialize up 1 Motor 1 # ... # ... # ...
  7. class def = end def = end
 end (motor) @motor

    motor
 (amount ) @motor.forward(amount) Desk
 initialize up # ... # ... 1
  8. class end class end = new new = new new

    ; ; @standing_desk . ( . ) @electrical_standing_desk . ( . ) Motor ElectricMotor # 手動 # 電動 Desk Motor Desk ElectricMotor
  9. class end class end class < def = new end

    end @discount . @discount.call(@order)
 DiscountService AnniversaryDiscountService CheckoutController ApplicationController create DiscountService # ... # ...
  10. class DiscountService end class AnniversaryDiscountService end class CheckoutController < ApplicationController

    def create @discount.call(@order)
 # ... end # ... end @discount . = new AnniversaryDiscountService
  11. class < def = end def = case when then

    new else new end end end @discount discount_service @discount.call(@order)
 @discount_service .current_store_event . . CheckoutController ApplicationController create discount_service # ... # ... Settings :anniversary AnniversaryDiscountService DiscountService
  12. # Which is highest?

 # ... # ... class def

    end end
 class def end end class < def = end end (amount, ); (order); @discount discount_service
 Order add_discount GeneralDiscountService call CheckoutController ApplicationController create reason:
  13. class def end end class < def = end end

    class < def end end (text); res commander.call(...) client.reply(res) TextCommander call LineBotController ApplicationController callback MessengerBotController ApplicationController callback # ... # ...
  14. class < def case in in end end end resolve(

    ).call(connect_params) => result render result.value, => result render result.failure, ConnectController ApplicationController create 'notify.connect' Success json: status: :created Failure json: status: :unprocessable_entity # ...
  15. module class < include private def end def ** =

    new end end end [ ] step try , :: :: (input) ( , , ) notify :: :: . ( token, type) notifies.save(notify) Notify Connect BaseOperation validate create Deps notifies: :validate :create catch: Notify Errors NotifyAlreadyExists token: type: Notify Entities Notify token: type: 'notify_repository' # ...
  16. module module class attr_reader def = = end end end

    end , ( , ) @token token @type type Notify Entities Notify initialize :token :type token: type: # ...
  17. # ActiveRecord model # API client class def = new

    end end class def end end (entity) notify . notify.assign_attributes(entity.to_h) notify.save! (entity) .upsert(entity.to_h) NotifyRepository save NotifyRepository save NotifyConnection NotifierAPI