class Terrestrial::Adapters::MemoryAdapter::Upsert
Small amount of code necessary to simulate upserts with Sequel's API
Attributes
dataset[R]
target[R]
update_attributes[R]
Public Class Methods
new(dataset, target:, update:)
click to toggle source
# File lib/terrestrial/adapters/memory_adapter.rb, line 275 def initialize(dataset, target:, update:) @dataset = dataset @target = target @update_attributes = update end
Public Instance Methods
attempt_update(row_id)
click to toggle source
# File lib/terrestrial/adapters/memory_adapter.rb, line 292 def attempt_update(row_id) dataset.where(row_id).update(update_attributes) end
insert(row)
click to toggle source
# File lib/terrestrial/adapters/memory_adapter.rb, line 284 def insert(row) dataset.insert(row) rescue DuplicateKeyError => e if target_matches?(e.key) attempt_update(e.row_id) end end
target_matches?(key)
click to toggle source
# File lib/terrestrial/adapters/memory_adapter.rb, line 296 def target_matches?(key) key.sort == Array(target).sort end