class HubLink::Insert

Attributes

row[R]
target[R]

Public Class Methods

new(row:, target:) click to toggle source
# File lib/hub_link/insert.rb, line 3
def initialize(row:, target:)
  @row = row
  @target = target
end

Public Instance Methods

run() click to toggle source
# File lib/hub_link/insert.rb, line 8
def run
  record.update! importable_attributes
end

Private Instance Methods

importable_attributes() click to toggle source
# File lib/hub_link/insert.rb, line 26
def importable_attributes
  row.slice(*target_columns)
end
primary_key() click to toggle source
# File lib/hub_link/insert.rb, line 22
def primary_key
  target.primary_key
end
primary_key_value() click to toggle source
# File lib/hub_link/insert.rb, line 18
def primary_key_value
  row[primary_key]
end
record() click to toggle source
# File lib/hub_link/insert.rb, line 14
def record
  target.find_or_initialize_by(primary_key => primary_key_value)
end
target_columns() click to toggle source
# File lib/hub_link/insert.rb, line 30
def target_columns
  target.columns.map(&:name).map(&:to_sym)
end