Module: Trailblazer::Operation::Contract::Build

Defined in:
lib/trailblazer/operation/contract.rb

Class Method Summary collapse

Class Method Details

.for(operation, options, name: "default", constant: nil, builder: nil) ⇒ Object

bla build contract at runtime.



19
20
21
22
23
24
25
26
27
28
# File 'lib/trailblazer/operation/contract.rb', line 19

def self.for(operation, options, name:"default", constant:nil, builder: nil)
  # TODO: we could probably clean this up a bit at some point.
  contract_class = constant || options["contract.#{name}.class"]
  model          = options["model"] # FIXME: model.default
  name           = "contract.#{name}"

  return options[name] = Option::KW.(builder).(operation, options, constant: contract_class, name: name) if builder

  options[name] = contract_class.new(model)
end