class ROM::FMP::Commands::Update

Public Instance Methods

change(original) click to toggle source
# File lib/rom/fmp/commands/update.rb, line 27
def change(original)
  self.class.new(relation, options.merge(original: original))
end
execute(tuple) click to toggle source
# File lib/rom/fmp/commands/update.rb, line 14
def execute(tuple)
  attributes = input[tuple]
  validator.call(attributes)

  changed = diff(attributes.to_h)

  if changed.any?
    update(changed)
  else
    []
  end
end
primary_key() click to toggle source
# File lib/rom/fmp/commands/update.rb, line 38
def primary_key
  relation.primary_key
end
update(tuple) click to toggle source
# File lib/rom/fmp/commands/update.rb, line 31
def update(tuple)
  pks = relation.map { |t| t[primary_key] }
  dataset = relation.dataset
  dataset.update(tuple)
  dataset.unfiltered.where(primary_key => pks).to_a
end

Private Instance Methods

diff(tuple) click to toggle source
# File lib/rom/fmp/commands/update.rb, line 44
def diff(tuple)
  if original
    Hash[tuple.to_a - (tuple.to_a & original.to_a)]
  else
    tuple
  end
end