Class: HashParams::HPHash
- Inherits:
-
Hash
- Object
- Hash
- HashParams::HPHash
- Defined in:
- lib/hash_params/hash_validator.rb
Instance Attribute Summary collapse
-
#validation_errors ⇒ Object
Returns the value of attribute validation_errors.
Instance Method Summary collapse
-
#initialize(args = nil) ⇒ HPHash
constructor
A new instance of HPHash.
- #set_key_value(key, value, symbolize_key, make_method) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(args = nil) ⇒ HPHash
Returns a new instance of HPHash.
7 8 9 10 |
# File 'lib/hash_params/hash_validator.rb', line 7 def initialize(args=nil) @validation_errors=[] super(args) end |
Instance Attribute Details
#validation_errors ⇒ Object
Returns the value of attribute validation_errors.
5 6 7 |
# File 'lib/hash_params/hash_validator.rb', line 5 def validation_errors @validation_errors end |
Instance Method Details
#set_key_value(key, value, symbolize_key, make_method) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/hash_params/hash_validator.rb', line 16 def set_key_value(key, value, symbolize_key, make_method) key = key.to_s.to_sym if symbolize_key if make_method singleton_class.module_eval do define_method key.to_s.to_sym do value end end end self[key]=value end |
#valid? ⇒ Boolean
12 13 14 |
# File 'lib/hash_params/hash_validator.rb', line 12 def valid? @validation_errors.empty? end |