Module: Actionizer::ClassMethods
- Defined in:
- lib/actionizer.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/actionizer.rb', line 15
def method_missing(method_name, *args, &block)
instance = new(*args)
if instance.respond_to?(method_name)
error = defined_inputs.check_for_param_error(method_name, *args)
raise ArgumentError, error if error
instance.tap(&method_name).output
else
super
end
rescue Actionizer::Failure => af
af.output
end
|
Instance Method Details
34
35
36
|
# File 'lib/actionizer.rb', line 34
def defined_inputs
@defined_inputs ||= Actionizer::Inputs.new
end
|
38
39
40
41
42
43
44
45
46
|
# File 'lib/actionizer.rb', line 38
def inputs_for(method)
raise ArgumentError, 'inputs_for requires a block' if !block_given?
defined_inputs.start(method)
yield
defined_inputs.end
raise 'You must define at least one optional or required param' if defined_inputs.no_params_declared?(method)
end
|
#optional(param) ⇒ Object
48
49
50
51
52
|
# File 'lib/actionizer.rb', line 48
def optional(param)
raise 'You must call optional from inside an inputs_for block' if defined_inputs.outside_inputs_for_block?
defined_inputs.add(param: param, required: false)
end
|
#required(param) ⇒ Object
54
55
56
57
58
|
# File 'lib/actionizer.rb', line 54
def required(param)
raise 'You must call required from inside an inputs_for block' if defined_inputs.outside_inputs_for_block?
defined_inputs.add(param: param, required: true)
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
30
31
32
|
# File 'lib/actionizer.rb', line 30
def respond_to_missing?(method_name, include_private = false)
new.respond_to?(method_name, include_private)
end
|