Class: AffiliateWindow::ETL::Loader
- Inherits:
-
Object
- Object
- AffiliateWindow::ETL::Loader
- Defined in:
- lib/affiliate_window/etl/loader.rb
Instance Attribute Summary collapse
-
#database ⇒ Object
Returns the value of attribute database.
Instance Method Summary collapse
-
#initialize(database:) ⇒ Loader
constructor
A new instance of Loader.
- #load(attributes) ⇒ Object
Constructor Details
#initialize(database:) ⇒ Loader
Returns a new instance of Loader.
6 7 8 |
# File 'lib/affiliate_window/etl/loader.rb', line 6 def initialize(database:) self.database = database end |
Instance Attribute Details
#database ⇒ Object
Returns the value of attribute database.
4 5 6 |
# File 'lib/affiliate_window/etl/loader.rb', line 4 def database @database end |
Instance Method Details
#load(attributes) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/affiliate_window/etl/loader.rb', line 10 def load(attributes) record_type = attributes.delete(:record_type) attributes.delete_if { |_, v| v.nil? } model = database.model(record_type) identity = attributes.slice(*model.identity) if (record = model.find_by(identity)) record.update!(attributes) else model.create!(attributes) end end |