Class: ETL::Control::ModelSource
- Defined in:
- lib/etl/control/source/model_source.rb
Overview
:nodoc:
Instance Attribute Summary
Attributes inherited from Source
#configuration, #control, #definition, #local_base, #store_locally
Instance Method Summary collapse
Methods inherited from Source
class_for_name, #errors, #initialize, #last_local_file, #last_local_file_trigger, #local_directory, #local_file, #local_file_trigger, #read_locally, #timestamp
Constructor Details
This class inherits a constructor from ETL::Control::Source
Instance Method Details
#columns ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/etl/control/source/model_source.rb', line 8 def columns case definition when Array definition.collect(&:to_sym) when Hash definition.keys.collect(&:to_sym) else raise "Definition must be either an Array or a Hash" end end |
#each(&block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/etl/control/source/model_source.rb', line 27 def each(&block) railsmodel.to_s.camelize.constantize.find(:all,:order=>order).each do |row| result_row = ETL::Row.new result_row.source = self columns.each do |column| result_row[column.to_sym] = row.send(column) end yield result_row end end |
#order ⇒ Object
23 24 25 |
# File 'lib/etl/control/source/model_source.rb', line 23 def order configuration[:order] || "id" end |
#railsmodel ⇒ Object
19 20 21 |
# File 'lib/etl/control/source/model_source.rb', line 19 def railsmodel configuration[:model] end |