Module: SexyScopes::ActiveRecord::ClassMethods

Defined in:
lib/sexy_scopes/active_record/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#attribute(name) ⇒ Object

Note:

Please note that no exception is raised if no such column actually exists.

Creates and extends an Arel Attribute representing the table’s column with the given name.

Examples:

where attribute(:score) > 1000

Parameters:

  • name (String, Symbol)

    The attribute name



14
15
16
17
# File 'lib/sexy_scopes/active_record/class_methods.rb', line 14

def attribute(name)
  attribute = arel_table[name]
  SexyScopes.extend_expression(attribute)
end

#sql_literal(expression) ⇒ Object Also known as: sql

Creates and extends an Arel SqlLiteral instance for the given expression, first converted to a string using to_s.

Examples:

where sql('LENGTH(email)') > 200

Parameters:

  • expression (String, #to_s)

    Any SQL expression.



27
28
29
30
31
32
# File 'lib/sexy_scopes/active_record/class_methods.rb', line 27

def sql_literal(expression)
  ::Arel.sql(expression.to_s).tap do |literal|
    SexyScopes.extend_expression(literal)
    SexyScopes.extend_predicate(literal)
  end
end