Module: ESA::Filters::AccountableFilter
- Defined in:
- lib/esa/filters/accountable_filter.rb
Defined Under Namespace
Modules: ObjectAccountable, TransactionAccountable
Class Method Summary
collapse
Class Method Details
.make_fragments(type, accountable) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/esa/filters/accountable_filter.rb', line 16
def self.make_fragments(type, accountable)
if accountable.is_a? ActiveRecord::Relation
[accountable.select("`#{accountable.table_name}`.`#{accountable.primary_key}` AS id, '#{type}' AS type").to_sql.squish]
elsif accountable.is_a? ActiveRecord::Base
["SELECT #{accountable.id} AS id, '#{type}' AS type"]
elsif accountable.is_a? Integer
["SELECT #{accountable} AS id, '#{type}' AS type"]
elsif accountable.respond_to? :each
accountable.map{|a| make_fragments(type, a)}.flatten
else
[]
end
end
|
.make_union_query(definitions = {}) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/esa/filters/accountable_filter.rb', line 4
def self.make_union_query(definitions = {})
fragments = definitions.map do |type,accountable|
make_fragments(type, accountable)
end.flatten
if fragments.count > 0
fragments.join(' UNION ')
else
"SELECT -1 AS id, 'Nothing' AS type"
end
end
|