Class: HashParams::HPHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/hash_params/hash_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_errorsObject

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

Returns:

  • (Boolean)


12
13
14
# File 'lib/hash_params/hash_validator.rb', line 12

def valid?
  @validation_errors.empty?
end