Class: TempTable::Fetch
- Inherits:
-
Object
- Object
- TempTable::Fetch
- Defined in:
- lib/temp_table/fetch.rb
Instance Attribute Summary collapse
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#table_name ⇒ Object
Returns the value of attribute table_name.
Instance Method Summary collapse
-
#initialize(table_name, conditions = nil) ⇒ Fetch
constructor
A new instance of Fetch.
- #perform ⇒ Object
Constructor Details
#initialize(table_name, conditions = nil) ⇒ Fetch
Returns a new instance of Fetch.
7 8 9 10 |
# File 'lib/temp_table/fetch.rb', line 7 def initialize(table_name, conditions = nil) @table_name = table_name @conditions = conditions end |
Instance Attribute Details
#conditions ⇒ Object
Returns the value of attribute conditions.
5 6 7 |
# File 'lib/temp_table/fetch.rb', line 5 def conditions @conditions end |
#table_name ⇒ Object
Returns the value of attribute table_name.
5 6 7 |
# File 'lib/temp_table/fetch.rb', line 5 def table_name @table_name end |
Instance Method Details
#perform ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/temp_table/fetch.rb', line 12 def perform query = "SELECT * FROM #{table_name}" if conditions.present? condition_strings = conditions.map do |column, value| "#{column} = #{ActiveRecord::Base.connection.quote(value)}" end query += " WHERE #{condition_strings.join(' AND ')}" end ActiveRecord::Base.connection.execute(query).to_a end |