Module: Searchlogic::NamedScopes::Ordering

Included in:
ActiveRecord::Base
Defined in:
lib/searchlogic/named_scopes/ordering.rb

Overview

Handles dynamically creating named scopes for ordering by columns. Example:

User.ascend_by_id
User.descend_by_username

See the README for a more detailed explanation.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/searchlogic/named_scopes/ordering.rb', line 19

def method_missing(name, *args, &block)
  if name == :order
    named_scope name, lambda { |scope_name|
      return {} if !condition?(scope_name)
      send(scope_name).proxy_options
    }
    send(name, *args)
  elsif details = ordering_condition_details(name)
    create_ordering_conditions(details[:column])
    send(name, *args)
  else
    super
  end
end

Instance Method Details

#condition?(name) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


10
11
12
# File 'lib/searchlogic/named_scopes/ordering.rb', line 10

def condition?(name) # :nodoc:
  super || ordering_condition?(name)
end