Class: ActiveRecordSeek::Query
Instance Method Summary
collapse
#after_initialize, #initialize, #instance_variable_reset, #instance_variable_yield, #set
Instance Method Details
#active_record_query=(new_active_record_query) ⇒ Object
9
10
11
12
|
# File 'lib/active_record_seek/query.rb', line 9
def active_record_query=(new_active_record_query)
instance_variable_reset(:@where_sql)
@active_record_query = new_active_record_query
end
|
#adapter_name ⇒ Object
23
24
25
|
# File 'lib/active_record_seek/query.rb', line 23
def adapter_name
model.connection.adapter_name
end
|
#apply(components) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/active_record_seek/query.rb', line 47
def apply(components)
to_active_record_query.seek_or(self) do |this|
components.group_by(&:namespace).each do |namespace, namespace_components|
case namespace
when "unscoped"
namespace_components.each do |component|
add_query { component.apply(self) }
end
else
add_query do |namespace_query|
namespace_components.each do |component|
namespace_query = component.apply(namespace_query)
end
namespace_query
end
end
end
end
end
|
#arel_column(column_name) ⇒ Object
27
28
29
|
# File 'lib/active_record_seek/query.rb', line 27
def arel_column(column_name)
arel_table[column_name]
end
|
#has_where_sql? ⇒ Boolean
43
44
45
|
# File 'lib/active_record_seek/query.rb', line 43
def has_where_sql?
to_where_sql.present?
end
|
#merge_where_sql(other_query) ⇒ Object
31
32
33
|
# File 'lib/active_record_seek/query.rb', line 31
def merge_where_sql(other_query)
to_active_record_query.where(other_query.to_seek_query.to_where_sql(enclose_with_parentheses: false))
end
|
#model ⇒ Object
19
20
21
|
# File 'lib/active_record_seek/query.rb', line 19
def model
to_active_record_query.klass
end
|
#to_seek_query ⇒ Object
15
16
17
|
# File 'lib/active_record_seek/query.rb', line 15
def to_seek_query
self
end
|
#to_where_sql(enclose_with_parentheses: true) ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/active_record_seek/query.rb', line 35
def to_where_sql(enclose_with_parentheses: true)
if !instance_variable_defined?(:@where_sql)
@where_sql = active_record_query.reorder(nil).to_sql.split(" WHERE ", 2)[1].to_s.strip
end
return "" if @where_sql.blank?
enclose_with_parentheses ? "(#{@where_sql})" : @where_sql
end
|