Class: Ransack::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/ransack_abbreviator/ransack_extensions/search.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *args) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/ransack_abbreviator/ransack_extensions/search.rb', line 6

def method_missing(method_id, *args)
  method_name = method_id.to_s
  writer = method_name.sub!(/\=$/, '')
  # Decode abbreviation (if it is indeed an abbreviation) so Ransack is happy
  decoded_param = self.context.decode_parameter(method_name)
  decoded_str = writer ? "#{decoded_param}=" : decoded_param
  ransack_method_missing(decoded_str.to_sym, *args)
end

Instance Method Details

#build(params) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/ransack_abbreviator/ransack_extensions/search.rb', line 15

def build(params)
  # Loop through each of the params and test if any contain abbreviations. If so, convert them to the normal Ransack language
  new_params = {}
  collapse_multiparameter_attributes!(params.with_indifferent_access).each do |key, value|
    decoded_param = self.context.decode_parameter(key)
    new_params[decoded_param] = value
  end

  ransack_search_build(new_params)
end

#ransack_method_missingObject



4
# File 'lib/ransack_abbreviator/ransack_extensions/search.rb', line 4

alias_method :ransack_method_missing, :method_missing

#ransack_search_buildObject



3
# File 'lib/ransack_abbreviator/ransack_extensions/search.rb', line 3

alias_method :ransack_search_build, :build