Class: ParamsChecker::ParamChecker::NestedHashsChecker
- Inherits:
-
Object
- Object
- ParamsChecker::ParamChecker::NestedHashsChecker
- 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(nested_hash) ⇒ Object
- #formatted_nested_hashs ⇒ Object
-
#initialize(key = '', fields = {}, opts = {}, context = {}) ⇒ NestedHashsChecker
constructor
A new instance of NestedHashsChecker.
Constructor Details
#initialize(key = '', fields = {}, opts = {}, context = {}) ⇒ NestedHashsChecker
160 161 162 163 164 165 |
# File 'lib/params_checker/param_checker.rb', line 160 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.
198 199 200 |
# File 'lib/params_checker/param_checker.rb', line 198 def class @class end |
#context ⇒ Object
Returns the value of attribute context.
198 199 200 |
# File 'lib/params_checker/param_checker.rb', line 198 def context @context end |
#fields ⇒ Object
Returns the value of attribute fields.
198 199 200 |
# File 'lib/params_checker/param_checker.rb', line 198 def fields @fields end |
#key ⇒ Object
Returns the value of attribute key.
198 199 200 |
# File 'lib/params_checker/param_checker.rb', line 198 def key @key end |
#opts ⇒ Object
Returns the value of attribute opts.
198 199 200 |
# File 'lib/params_checker/param_checker.rb', line 198 def opts @opts end |
Instance Method Details
#add_error(message = '') ⇒ Object
194 195 196 |
# File 'lib/params_checker/param_checker.rb', line 194 def add_error( = '') errors.add(key, ) end |
#call ⇒ Object
167 168 169 170 171 |
# File 'lib/params_checker/param_checker.rb', line 167 def call return nil if fields[key][:allow_nil] && opts[key].nil? check_type && formatted_nested_hashs end |
#check_type ⇒ Object
188 189 190 191 192 |
# File 'lib/params_checker/param_checker.rb', line 188 def check_type valid = opts[key].is_a?(Array) add_error("This field's type must be array.") unless valid valid end |
#formatted_nested_hash(nested_hash) ⇒ Object
179 180 181 182 183 184 185 186 |
# File 'lib/params_checker/param_checker.rb', line 179 def formatted_nested_hash nested_hash cmd = fields[key][:class].call(params: nested_hash, context: context, is_outest_hash: false) if cmd.success? cmd.result else add_error cmd.errors end end |
#formatted_nested_hashs ⇒ Object
173 174 175 176 177 |
# File 'lib/params_checker/param_checker.rb', line 173 def formatted_nested_hashs opts[key].map do |nested_hash| formatted_nested_hash(nested_hash) end end |