Class: BCDD::Process::InputSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/bcdd/process/input_spec.rb

Defined Under Namespace

Modules: MapContract

Constant Summary collapse

MapDefault =
->(options) do
  value = options[:default]

  return value unless value.is_a?(Proc)
  return value if value.lambda? && value.arity.zero?

  raise ArgumentError, 'Default value must be a lambda with zero arity'
end
MapNormalize =
->(options) do
  value = options[:normalize]

  return value if value.is_a?(Proc) && value.lambda?

  raise ArgumentError, 'normalize value must be a lambda with one arity'
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInputSpec

Returns a new instance of InputSpec.



45
46
47
# File 'lib/bcdd/process/input_spec.rb', line 45

def initialize
  @__result__ = {}
end

Instance Attribute Details

#__result__Object (readonly)

:nodoc:



43
44
45
# File 'lib/bcdd/process/input_spec.rb', line 43

def __result__
  @__result__
end

Instance Method Details

#attribute(name, **options) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/bcdd/process/input_spec.rb', line 49

def attribute(name, **options)
  name.is_a?(Symbol) or raise ArgumentError, "#{name.inspect} must be a Symbol"

  spec = {}
  spec[:default] = MapDefault[options] if options.key?(:default)
  spec[:normalize] = MapNormalize[options] if options.key?(:normalize)

  MapContract[options].then { spec[:contract] = _1 if _1 }

  __result__[name] = spec
end

#contractObject



61
62
63
# File 'lib/bcdd/process/input_spec.rb', line 61

def contract
  BCDD::Contract
end