Class: Actionizer::Inputs
- Inherits:
-
Object
- Object
- Actionizer::Inputs
- Defined in:
- lib/actionizer/inputs.rb
Instance Attribute Summary collapse
-
#declared_params_by_method ⇒ Object
readonly
Returns the value of attribute declared_params_by_method.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
Instance Method Summary collapse
- #add(args) ⇒ Object
- #check_for_param_error(method_name, params = {}) ⇒ Object
- #end ⇒ Object
-
#initialize ⇒ Inputs
constructor
A new instance of Inputs.
- #no_params_declared?(method) ⇒ Boolean
- #outside_inputs_for_block? ⇒ Boolean
- #start(method) ⇒ Object
Constructor Details
#initialize ⇒ Inputs
Returns a new instance of Inputs.
5 6 7 |
# File 'lib/actionizer/inputs.rb', line 5 def initialize @declared_params_by_method = {} end |
Instance Attribute Details
#declared_params_by_method ⇒ Object (readonly)
Returns the value of attribute declared_params_by_method.
3 4 5 |
# File 'lib/actionizer/inputs.rb', line 3 def declared_params_by_method @declared_params_by_method end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
3 4 5 |
# File 'lib/actionizer/inputs.rb', line 3 def method @method end |
Instance Method Details
#add(args) ⇒ Object
35 36 37 |
# File 'lib/actionizer/inputs.rb', line 35 def add(args) @declared_params_by_method[method][args.fetch(:param)] = { required: args.fetch(:required) } end |
#check_for_param_error(method_name, params = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/actionizer/inputs.rb', line 9 def check_for_param_error(method_name, params = {}) # If no inputs_for was declared, don't do any checking return false if !declared_params_by_method.key?(method_name) params.each_key do |param| return "Param #{param} not declared" if !declared_params_by_method.fetch(method_name).include?(param) end declared_params_by_method.fetch(method_name, {}).each_pair do |param, attrs| next if !attrs.fetch(:required) return "Param #{param} is required for #{method_name}" if !params.include?(param) end false end |
#end ⇒ Object
31 32 33 |
# File 'lib/actionizer/inputs.rb', line 31 def end @method = nil end |
#no_params_declared?(method) ⇒ Boolean
39 40 41 |
# File 'lib/actionizer/inputs.rb', line 39 def no_params_declared?(method) declared_params_by_method.fetch(method, {}).empty? end |
#outside_inputs_for_block? ⇒ Boolean
43 44 45 |
# File 'lib/actionizer/inputs.rb', line 43 def outside_inputs_for_block? method.nil? end |
#start(method) ⇒ Object
26 27 28 29 |
# File 'lib/actionizer/inputs.rb', line 26 def start(method) @method = method @declared_params_by_method[method] = {} end |