class HecksAdapters::SQLDatabase::Commands::Update

Upate a resource

Attributes

id[R]

Public Class Methods

new(attributes:, head:, id:) click to toggle source
# File lib/commands/update.rb, line 13
def initialize(attributes:, head:, id:)
  @attributes = attributes.clone
  @references = head.references
  @head_table = Table.factory([head]).first
  @id = id
end

Public Instance Methods

call() click to toggle source
# File lib/commands/update.rb, line 20
def call
  DB.transaction do
    update_references
    fetch_record
    update_record
  end
  self
end

Private Instance Methods

fetch_record() click to toggle source
# File lib/commands/update.rb, line 39
def fetch_record
  @record = DB[@head_table.name.to_sym].where(id: @id)
end
update_record() click to toggle source
# File lib/commands/update.rb, line 35
def update_record
  @record.update(@attributes)
end
update_references() click to toggle source
# File lib/commands/update.rb, line 31
def update_references
  UpdateValues.new(@references, @attributes, @head_table, @id).call
end