Module: BCDD::Value::Properties::Contract

Defined in:
lib/bcdd/ext/value.rb

Class Method Summary collapse

Class Method Details

.[](options) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/bcdd/ext/value.rb', line 21

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

  if contract
    required ? contract : (contract | nil)
  elsif required
    Contracts::NotNil
  end
end

.compose(options) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/bcdd/ext/value.rb', line 32

def self.compose(options)
  type = ::BCDD::Contract.type(options[:type]) if options.key?(:type)
  contract = ::BCDD::Contract[options[:contract]] if options.key?(:contract)
  respond_to = ::BCDD::Contract.respond_to(Array(options[:respond_to])) if options.key?(:respond_to)

  [type, contract, respond_to].compact!&.reduce(:&)
end