Class: Oxidized::SQL
Instance Method Summary
collapse
Methods inherited from Source
#map_group, #map_model, #node_var_interpolate
Instance Method Details
#load(node_want = nil) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/oxidized/source/sql.rb', line 21
def load(node_want = nil)
nodes = []
db = connect
query = db[@cfg.table.to_sym]
query = query.with_sql(@cfg.query) if @cfg.query?
query = query.where(@cfg.map.name.to_sym => node_want) if node_want
query.each do |node|
keys = {}
@cfg.map.each { |key, sql_column| keys[key.to_sym] = node_var_interpolate node[sql_column.to_sym] }
keys[:model] = map_model keys[:model] if keys.has_key? :model
keys[:group] = map_group keys[:group] if keys.has_key? :group
vars = {}
@cfg.vars_map.each do |key, sql_column|
vars[key.to_sym] = node_var_interpolate node[sql_column.to_sym]
end
keys[:vars] = vars unless vars.empty?
nodes << keys
end
db.disconnect
nodes
end
|