Module: Cadence::Concerns::Typed::ClassMethods

Defined in:
lib/cadence/concerns/typed.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#input_classObject (readonly)

Returns the value of attribute input_class.



12
13
14
# File 'lib/cadence/concerns/typed.rb', line 12

def input_class
  @input_class
end

Instance Method Details

#execute_in_context(context, input) ⇒ Object



14
15
16
17
18
# File 'lib/cadence/concerns/typed.rb', line 14

def execute_in_context(context, input)
  input = input_class[*input] if input_class

  super(context, input)
end

#input(klass = nil, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cadence/concerns/typed.rb', line 20

def input(klass = nil, &block)
  if klass
    unless klass.is_a?(Dry::Types::Type)
      raise 'Unsupported input class. Use one of the provided Cadence::Types'
    end
    @input_class = klass
  else
    @input_class = generate_struct
    @input_class.instance_eval(&block)
  end
end