Module: Searchlogic::NamedScopes::Ordering
- 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.
Defined Under Namespace
Modules: ClassOverrideMethods, InstanceOverrideMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#condition?(name) ⇒ Boolean
:nodoc:.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/searchlogic/named_scopes/ordering.rb', line 44 def method_missing(name, *args, &block) if name == :order scope name, lambda { |scope_name| return {} if !condition?(scope_name) send(scope_name). } send(name, *args) end if details = ordering_condition_details(name) create_ordering_conditions(details[:column]) send(name, *args) else super end end |
Class Method Details
.included(base) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/searchlogic/named_scopes/ordering.rb', line 14 def self.included(base) #this overrides the 'new' method in any class including Ordering -- then when called, new overrides the 'order' method #overriding is not a simple matter in Ruby because includes put the modules below the class in the superclass sequence #this keeps the code cleaner by avoiding alias_method_chain (monkey patching) (class << base; self; end).send(:include, ClassOverrideMethods) end |
Instance Method Details
#condition?(name) ⇒ Boolean
:nodoc:
10 11 12 |
# File 'lib/searchlogic/named_scopes/ordering.rb', line 10 def condition?(name) # :nodoc: super || ordering_condition?(name) end |