module Trailblazer::Macro::Contract::Build

Public Class Methods

call(options, circuit_options, name: "default", constant: nil, builder: nil) click to toggle source

Build contract at runtime.

# File lib/trailblazer/macro/contract/build.rb, line 19
def self.call(options, circuit_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"] # DISCUSS: Injection possible here?
  model          = options[:model]
  name           = :"contract.#{name}"

  options[name] = if builder
                    call_builder(options, circuit_options, builder: builder, constant: contract_class, name: name)
                  else
                    contract_class.new(model)
                  end
end
call_builder(ctx, circuit_options, builder: raise, constant: raise, name: raise) click to toggle source
# File lib/trailblazer/macro/contract/build.rb, line 32
def self.call_builder(ctx, circuit_options, builder: raise, constant: raise, name: raise)
  tmp_options = ctx.to_hash.merge(
    constant: constant,
    name:     name
  )

  Trailblazer::Option(builder).(ctx, keyword_arguments: tmp_options, **circuit_options) # TODO: why can't we build the {builder} at compile time?
end