Class: ParamsChecker::ParamChecker::NestedHashChecker
- Inherits:
-
Object
- Object
- ParamsChecker::ParamChecker::NestedHashChecker
- Includes:
- SimpleCommand
- Defined in:
- lib/params_checker/param_checker.rb
Instance Attribute Summary collapse
-
#class ⇒ Object
Returns the value of attribute class.
-
#context ⇒ Object
Returns the value of attribute context.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#key ⇒ Object
Returns the value of attribute key.
-
#opts ⇒ Object
Returns the value of attribute opts.
Instance Method Summary collapse
- #add_error(message = '') ⇒ Object
- #call ⇒ Object
- #check_type ⇒ Object
- #formatted_nested_hash ⇒ Object
-
#initialize(key = '', fields = {}, opts = {}, context = {}) ⇒ NestedHashChecker
constructor
A new instance of NestedHashChecker.
Constructor Details
#initialize(key = '', fields = {}, opts = {}, context = {}) ⇒ NestedHashChecker
Returns a new instance of NestedHashChecker.
123 124 125 126 127 128 |
# File 'lib/params_checker/param_checker.rb', line 123 def initialize(key = '', fields = {}, opts = {}, context = {}) @key = key @fields = fields @opts = opts @context = context end |
Instance Attribute Details
#class ⇒ Object
Returns the value of attribute class.
155 156 157 |
# File 'lib/params_checker/param_checker.rb', line 155 def class @class end |
#context ⇒ Object
Returns the value of attribute context.
155 156 157 |
# File 'lib/params_checker/param_checker.rb', line 155 def context @context end |
#fields ⇒ Object
Returns the value of attribute fields.
155 156 157 |
# File 'lib/params_checker/param_checker.rb', line 155 def fields @fields end |
#key ⇒ Object
Returns the value of attribute key.
155 156 157 |
# File 'lib/params_checker/param_checker.rb', line 155 def key @key end |
#opts ⇒ Object
Returns the value of attribute opts.
155 156 157 |
# File 'lib/params_checker/param_checker.rb', line 155 def opts @opts end |
Instance Method Details
#add_error(message = '') ⇒ Object
151 152 153 |
# File 'lib/params_checker/param_checker.rb', line 151 def add_error( = '') errors.add(key, ) end |
#call ⇒ Object
130 131 132 133 134 |
# File 'lib/params_checker/param_checker.rb', line 130 def call return nil if fields[key][:allow_nil] && opts[key].nil? check_type && formatted_nested_hash end |
#check_type ⇒ Object
145 146 147 148 149 |
# File 'lib/params_checker/param_checker.rb', line 145 def check_type valid = opts[key].is_a?(ActionController::Parameters) || opts[key].is_a?(Hash) add_error("This field's type must be object or ActionController::Parameters.") unless valid valid end |
#formatted_nested_hash ⇒ Object
136 137 138 139 140 141 142 143 |
# File 'lib/params_checker/param_checker.rb', line 136 def formatted_nested_hash cmd = fields[key][:class].call(params:opts[key], context: context, is_outest_hash: false) if cmd.success? cmd.result else add_error cmd.errors end end |