Class: OrderQuery::SQL::Condition

Inherits:
Object
  • Object
show all
Defined in:
lib/order_query/sql/condition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(condition, scope) ⇒ Condition

Returns a new instance of Condition.



6
7
8
9
# File 'lib/order_query/sql/condition.rb', line 6

def initialize(condition, scope)
  @condition = condition
  @scope = scope
end

Instance Attribute Details

#conditionObject (readonly)

Returns the value of attribute condition.



4
5
6
# File 'lib/order_query/sql/condition.rb', line 4

def condition
  @condition
end

#scopeObject (readonly)

Returns the value of attribute scope.



4
5
6
# File 'lib/order_query/sql/condition.rb', line 4

def scope
  @scope
end

Instance Method Details

#column_nameObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/order_query/sql/condition.rb', line 11

def column_name
  @column_name ||= begin
    sql = condition.options[:sql]
    if sql
      sql = sql.call if sql.respond_to?(:call)
      sql
    else
      connection.quote_table_name(scope.table_name) + '.' + connection.quote_column_name(condition.name)
    end
  end
end

#quote(value) ⇒ Object



23
24
25
# File 'lib/order_query/sql/condition.rb', line 23

def quote(value)
  connection.quote value
end