Class: ROM::CSV::Commands::Update
- Inherits:
-
ROM::Commands::Update
- Object
- ROM::Commands::Update
- ROM::CSV::Commands::Update
- Defined in:
- lib/rom/csv/commands/update.rb
Instance Method Summary collapse
- #dataset ⇒ Object
- #execute(tuple) ⇒ Object
- #original_dataset ⇒ Object
- #update(tuple) ⇒ Object
- #update_dataset(index, tuple) ⇒ Object
Instance Method Details
#dataset ⇒ Object
38 39 40 |
# File 'lib/rom/csv/commands/update.rb', line 38 def dataset relation.dataset end |
#execute(tuple) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/rom/csv/commands/update.rb', line 10 def execute(tuple) attributes = input[tuple] validator.call(attributes) tuple = attributes.to_h update(tuple) end |
#original_dataset ⇒ Object
42 43 44 |
# File 'lib/rom/csv/commands/update.rb', line 42 def original_dataset source.dataset end |
#update(tuple) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rom/csv/commands/update.rb', line 18 def update(tuple) original_data = original_dataset.to_a output = [] dataset.each do |dataset_tuple| index = original_data.index(dataset_tuple) update_dataset(index, tuple) output << original_dataset.data[index].to_hash end original_dataset.sync! output end |
#update_dataset(index, tuple) ⇒ Object
32 33 34 35 36 |
# File 'lib/rom/csv/commands/update.rb', line 32 def update_dataset(index, tuple) tuple.each do |key, value| original_dataset.data[index][key] = value end end |