Class: WhalesORM::Relation
- Inherits:
-
BasicObject
- Defined in:
- lib/relation.rb
Instance Method Summary
collapse
Constructor Details
#initialize(params, class_name) ⇒ Relation
Returns a new instance of Relation.
6
7
8
9
|
# File 'lib/relation.rb', line 6
def initialize(params, class_name)
@params = params
@class_name = class_name
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &blk) ⇒ Object
19
20
21
22
|
# File 'lib/relation.rb', line 19
def method_missing(method, *args, &blk)
results = self.execute
results.send(method, *args, &blk)
end
|
Instance Method Details
#execute ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/relation.rb', line 28
def execute
query = " SELECT\n *\n FROM\n \#{@class_name.table_name}\n WHERE\n \#{where_line}\n SQL\n\n results = ::DBConnection.execute(query, *@params.values)\n @class_name.parse_all(results)\nend\n"
|
#load ⇒ Object
24
25
26
|
# File 'lib/relation.rb', line 24
def load
execute
end
|
#where(params) ⇒ Object
11
12
13
|
# File 'lib/relation.rb', line 11
def where(params)
@params.merge(params)
end
|
#where_line ⇒ Object
15
16
17
|
# File 'lib/relation.rb', line 15
def where_line
@params.keys.map { |key| "#{key} = ?" }.join(" AND ")
end
|