Module: Searchlogic::NamedScopes::Conditions

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

Overview

Handles dynamically creating named scopes for columns. It allows you to do things like:

User.first_name_like("ben")
User.id_lt(10)

Notice the constants in this class, they define which conditions Searchlogic provides.

See the README for a more detailed explanation.

Constant Summary collapse

COMPARISON_CONDITIONS =
{
  :equals => [:is, :eq],
  :does_not_equal => [:not_equal_to, :is_not, :not, :ne],
  :less_than => [:lt, :before],
  :less_than_or_equal_to => [:lte],
  :greater_than => [:gt, :after],
  :greater_than_or_equal_to => [:gte],
}
WILDCARD_CONDITIONS =
{
  :like => [:contains, :includes],
  :not_like => [],
  :begins_with => [:bw],
  :not_begin_with => [:does_not_begin_with],
  :ends_with => [:ew],
  :not_end_with => [:does_not_end_with]
}
BOOLEAN_CONDITIONS =
{
  :null => [:nil],
  :not_null => [:not_nil],
  :empty => [],
  :blank => [],
  :not_blank => [:present]
}
CONDITIONS =
{}
PRIMARY_CONDITIONS =
CONDITIONS.keys
ALIAS_CONDITIONS =
CONDITIONS.values.flatten

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



64
65
66
67
68
69
70
71
# File 'lib/searchlogic/named_scopes/conditions.rb', line 64

def method_missing(name, *args, &block)
  if details = condition_details(name)
    create_condition(details[:column], details[:condition], args)
    send(name, *args)
  else
    super
  end
end

Instance Method Details

#condition?(name) ⇒ Boolean

Is the name of the method a valid condition that can be dynamically created?

Returns:

  • (Boolean)


53
54
55
# File 'lib/searchlogic/named_scopes/conditions.rb', line 53

def condition?(name)
  local_condition?(name)
end