Module: ServiceActor::Attributable::ClassMethods

Defined in:
lib/service_actor/attributable.rb

Instance Method Summary collapse

Instance Method Details

#inherited(child) ⇒ Object



17
18
19
20
21
22
# File 'lib/service_actor/attributable.rb', line 17

def inherited(child)
  super

  child.inputs.merge!(inputs)
  child.outputs.merge!(outputs)
end

#input(name, **arguments) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/service_actor/attributable.rb', line 24

def input(name, **arguments)
  ServiceActor::ArgumentsValidator.validate_origin_name(
    name, origin: :input
  )

  inputs[name] = arguments

  define_method(name) do
    result[name]
  end

  # To avoid method redefined warning messages.
  alias_method(name, name) if method_defined?(name)

  protected name
end

#inputsObject



41
42
43
# File 'lib/service_actor/attributable.rb', line 41

def inputs
  @inputs ||= {}
end

#output(name, **arguments) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/service_actor/attributable.rb', line 45

def output(name, **arguments)
  ServiceActor::ArgumentsValidator.validate_origin_name(
    name, origin: :output
  )

  outputs[name] = arguments

  define_method(name) do
    result[name]
  end
  protected name

  define_method(:"#{name}=") do |value|
    result[name] = value
  end
  protected :"#{name}="
end

#outputsObject



63
64
65
# File 'lib/service_actor/attributable.rb', line 63

def outputs
  @outputs ||= {}
end