Module: BCDD::Process::InputSpec::MapContract

Defined in:
lib/bcdd/process/input_spec.rb

Class Method Summary collapse

Class Method Details

.[](options) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/bcdd/process/input_spec.rb', line 7

def self.[](options)
  required = options.fetch(:required, true)

  if options.key?(:contract) || options.key?(:type) || options.key?(:validate)
    resolve(options).then { required ? _1 : (_1 | nil) }
  elsif required
    Contracts::NotNil
  end
end

.resolve(options) ⇒ Object



17
18
19
20
21
22
# File 'lib/bcdd/process/input_spec.rb', line 17

def self.resolve(options)
  type = ::BCDD::Contract.unit(options[:type]) if options.key?(:type)
  contract = ::BCDD::Contract[options[:contract]] if options.key?(:contract)

  type && contract ? (type & contract) : type || contract
end