Class: Qravan::Resource
- Inherits:
-
Object
- Object
- Qravan::Resource
- Defined in:
- lib/qravan/resource/resource.rb
Overview
Resource processing class
Instance Attribute Summary collapse
-
#cargo ⇒ Object
Returns the value of attribute cargo.
-
#connections ⇒ Object
Returns the value of attribute connections.
Instance Method Summary collapse
- #extract ⇒ Object
-
#initialize(name, data, cargo = {}) ⇒ Resource
constructor
A new instance of Resource.
- #sql ⇒ Object
- #validate ⇒ Object
- #where ⇒ Object
Constructor Details
#initialize(name, data, cargo = {}) ⇒ Resource
Returns a new instance of Resource.
7 8 9 10 11 12 |
# File 'lib/qravan/resource/resource.rb', line 7 def initialize(name, data, cargo = {}) @resource = name @resource_data = data @cargo ||= cargo @connections = cargo.connections end |
Instance Attribute Details
#cargo ⇒ Object
Returns the value of attribute cargo.
5 6 7 |
# File 'lib/qravan/resource/resource.rb', line 5 def cargo @cargo end |
#connections ⇒ Object
Returns the value of attribute connections.
5 6 7 |
# File 'lib/qravan/resource/resource.rb', line 5 def connections @connections end |
Instance Method Details
#extract ⇒ Object
18 19 20 21 |
# File 'lib/qravan/resource/resource.rb', line 18 def extract source_name = "#{cargo.models[@resource]["extract"]["source"]["name"]}_source" @connections[source_name.to_s].extract(sql) end |
#sql ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/qravan/resource/resource.rb', line 23 def sql [ :select, @resource_data["attributes"].join(","), :from, cargo.models[@resource]["extract"]["source"]["table"], where ].flatten.join(" ") end |
#validate ⇒ Object
14 15 16 |
# File 'lib/qravan/resource/resource.rb', line 14 def validate @resource_data end |
#where ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/qravan/resource/resource.rb', line 33 def where if @resource_data["conditions"] [ :where, @resource_data["conditions"].map { |k, v| "#{k}='#{v}'" } .join(" and ") ] else [""] end end |