Module: Eluvia::ParamsHandler
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/eluvia/handlers/params_handler.rb
Instance Method Summary collapse
Instance Method Details
#disassemble_filters(params) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/eluvia/handlers/params_handler.rb', line 25 def disassemble_filters(params) result = {} params.each do |key, value| split_key = key.to_s.split('__') result_component = result split_key.each_with_index do |key_component, index| if index + 1 == split_key.length # last component result_component[key_component.to_sym] = value else result_component[key_component.to_sym] = {} if result_component[key_component.to_sym].nil? result_component = result_component[key_component.to_sym] end end end result end |
#parse_json_param(value) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/eluvia/handlers/params_handler.rb', line 5 def parse_json_param(value) unless value.blank? if value.is_a?(String) JSON.parse(value) # This can produce JSON::ParserError which is translated to Eluvia::Errors::StandardError elsif value.is_a?(ActionController::Parameters) value.to_unsafe_h elsif value.is_a?(Array) result = [] value.each do |item| if item.is_a?(String) result << (JSON.parse(item) rescue item) # This can produce JSON::ParserError which is translated to Eluvia::Errors::StandardError elsif item.is_a?(ActionController::Parameters) result << item.to_unsafe_h end end result end end end |