Class: Lore::Select_Query
- Inherits:
-
Array
- Object
- Array
- Lore::Select_Query
show all
- Defined in:
- lib/lore/query.rb
Overview
Proxy class for Select queries.
Model.select { |x| ... } --> Select.new(Model, clause_parser)
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(model, what = nil, polymorphic = false, &block) ⇒ Select_Query
Returns a new instance of Select_Query.
12
13
14
15
16
17
18
|
# File 'lib/lore/query.rb', line 12
def initialize(model, what=nil, polymorphic=false, &block)
@model = model
@strategy = model.__select_strategy__
@what = what
@polymorphic = polymorphic
@clause_parser = yield(Clause_Parser.new(@model))
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
Any undefined method is interpreted as kicker call.
56
57
58
|
# File 'lib/lore/query.rb', line 56
def method_missing(meth, *args)
perform.__send__(meth, *args)
end
|
Instance Attribute Details
#clause_parser ⇒ Object
Returns the value of attribute clause_parser.
10
11
12
|
# File 'lib/lore/query.rb', line 10
def clause_parser
@clause_parser
end
|
Returns the value of attribute model.
10
11
12
|
# File 'lib/lore/query.rb', line 10
def model
@model
end
|
Instance Method Details
50
51
52
|
# File 'lib/lore/query.rb', line 50
def +(other)
perform + other.to_a
end
|
#each(&block) ⇒ Object
38
39
40
|
# File 'lib/lore/query.rb', line 38
def each(&block)
perform.each(&block)
end
|
#each_with_index(&block) ⇒ Object
41
42
43
|
# File 'lib/lore/query.rb', line 41
def each_with_index(&block)
perform.each_with_index(&block)
end
|
32
33
34
|
# File 'lib/lore/query.rb', line 32
def first
perform.first
end
|
35
36
37
|
# File 'lib/lore/query.rb', line 35
def last
perform.last
end
|
25
26
27
|
# File 'lib/lore/query.rb', line 25
def perform
@strategy.select_cached(@what, @clause_parser, @polymorphic)
end
|
#to_sql ⇒ Object
Also known as:
sql
20
21
22
|
# File 'lib/lore/query.rb', line 20
def to_sql
@strategy.select_query(@what, @clause_parser, @polymorphic)[:query]
end
|
#union(other) ⇒ Object
45
46
47
48
|
# File 'lib/lore/query.rb', line 45
def union(other)
@clause_parser.union(other)
return self
end
|