Class: RiderKick::UseCases::AbstractUseCase

Inherits:
Object
  • Object
show all
Defined in:
lib/rider_kick/use_cases/abstract_use_case.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contract) ⇒ AbstractUseCase

Returns a new instance of AbstractUseCase.



23
24
25
# File 'lib/rider_kick/use_cases/abstract_use_case.rb', line 23

def initialize(contract)
  @contract = contract
end

Class Method Details

.contract(base_contract = Contract, &proc) ⇒ Object



14
15
16
# File 'lib/rider_kick/use_cases/abstract_use_case.rb', line 14

def self.contract(base_contract = Contract, &proc)
  @contract ||= Class.new(base_contract, &proc)
end

.contract!(args) ⇒ Object



18
19
20
21
# File 'lib/rider_kick/use_cases/abstract_use_case.rb', line 18

def self.contract!(args)
  context  = args.fetch(:context, {})
  @results = @contract.new(context).call(args)
end

Instance Method Details

#build_parameter!Object



27
28
29
30
31
32
33
# File 'lib/rider_kick/use_cases/abstract_use_case.rb', line 27

def build_parameter!
  if @contract.success?
    Success(Hashie::Mash.new(@contract.to_h))
  else
    Failure(@contract.errors.to_h)
  end
end