Module: ActivateAdmin::ParamHelpers
- Defined in:
- lib/param_helpers.rb
Instance Method Summary collapse
- #blanks_to_nils!(hash) ⇒ Object
- #datetime_hashes_to_datetimes!(hash) ⇒ Object
- #file_hashes_to_files!(hash) ⇒ Object
- #fix_params! ⇒ Object
Instance Method Details
#blanks_to_nils!(hash) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/param_helpers.rb', line 30 def blanks_to_nils!(hash) hash.each { |k,v| if v.blank? hash[k] = nil elsif v.is_a? Array v.each_with_index { |x,i| v[i] = nil if x.blank? }.compact! elsif v.is_a? Hash blanks_to_nils!(v) end } end |
#datetime_hashes_to_datetimes!(hash) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/param_helpers.rb', line 10 def datetime_hashes_to_datetimes!(hash) hash.each { |k,v| if v.is_a?(Hash) and [:year, :month, :day, :hour, :min].all? { |x| v.has_key?(x.to_s) } hash[k] = Time.zone.local(v[:year].to_i, v[:month].to_i, v[:day].to_i, v[:hour].to_i, v[:min].to_i) elsif v.is_a?(Hash) datetime_hashes_to_datetimes!(v) end } end |
#file_hashes_to_files!(hash) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/param_helpers.rb', line 20 def file_hashes_to_files!(hash) hash.each { |k, v| if v.is_a?(Hash) and v[:tempfile] hash[k] = v[:tempfile] elsif v.is_a?(Hash) file_hashes_to_files!(v) end } end |
#fix_params! ⇒ Object
4 5 6 7 8 |
# File 'lib/param_helpers.rb', line 4 def fix_params! datetime_hashes_to_datetimes!(params) file_hashes_to_files!(params) blanks_to_nils!(params) end |