Class: CleanParams::Configuration
- Inherits:
-
Object
- Object
- CleanParams::Configuration
- Defined in:
- lib/clean_params.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
- #extract_params(controllerParams) ⇒ Object
- #get_value_from_params(val, controllerParams) ⇒ Object
- #search_hash(h, search) ⇒ Object
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
20 21 22 |
# File 'lib/clean_params.rb', line 20 def params @params end |
Instance Method Details
#extract_params(controllerParams) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/clean_params.rb', line 22 def extract_params(controllerParams) params.each do |key, val| self.class.send(:attr_accessor, key) instance_variable_set("@#{key}", get_value_from_params(val, controllerParams)) end end |
#get_value_from_params(val, controllerParams) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/clean_params.rb', line 29 def get_value_from_params(val, controllerParams) if val.is_a? String val = val.split(",") end val.each do |param| answer = search_hash(controllerParams, param) return answer if answer end nil # return nil if no match end |
#search_hash(h, search) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/clean_params.rb', line 40 def search_hash(h, search) return h[search] if h.fetch(search, nil) h.keys.each do |k| answer = search_hash(h[k], search) if h[k].is_a? Hash return answer if answer end nil end |