Class: Servactory::Context::Warehouse::Inputs
- Inherits:
-
Base
- Object
- Base
- Servactory::Context::Warehouse::Inputs
show all
- Defined in:
- lib/servactory/context/warehouse/inputs.rb
Instance Method Summary
collapse
Methods inherited from Base
#assign, #fetch
Constructor Details
#initialize(context, arguments = {}) ⇒ Inputs
Returns a new instance of Inputs.
7
8
9
10
11
|
# File 'lib/servactory/context/warehouse/inputs.rb', line 7
def initialize(context, arguments = {})
@context = context
super(arguments)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *_args) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/servactory/context/warehouse/inputs.rb', line 23
def method_missing(name, *_args)
input_name = @context.config.predicate_methods_enabled ? name.to_s.chomp("?").to_sym : name
input_value = @arguments.fetch(input_name) { raise_error_for(input_name) }
if name.to_s.end_with?("?") && @context.config.predicate_methods_enabled
Servactory::Utils.query_attribute(input_value)
else
input_value
end
end
|
Instance Method Details
#merge!(arguments) ⇒ Object
17
18
19
|
# File 'lib/servactory/context/warehouse/inputs.rb', line 17
def merge!(arguments)
@arguments.merge!(arguments)
end
|
#names ⇒ Object
13
14
15
|
# File 'lib/servactory/context/warehouse/inputs.rb', line 13
def names
@arguments.keys
end
|
#raise_error_for(input_name) ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/servactory/context/warehouse/inputs.rb', line 41
def raise_error_for(input_name)
message_text = @context.send(:servactory_service_info).translate(
"inputs.undefined.for_fetch",
input_name:
)
@context.fail_input!(input_name, message: message_text)
end
|
#respond_to_missing?(name) ⇒ Boolean
35
36
37
|
# File 'lib/servactory/context/warehouse/inputs.rb', line 35
def respond_to_missing?(name, *)
@arguments.fetch(name) { raise_error_for(name) }
end
|