Module: Stagehand::Key

Extended by:
Key
Included in:
Key
Defined in:
lib/stagehand/key.rb

Instance Method Summary collapse

Instance Method Details

#generate(staging_record, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/stagehand/key.rb', line 5

def generate(staging_record, options = {})
  case staging_record
  when Staging::CommitEntry
    id = staging_record.record_id || staging_record.id
    table_name = staging_record.table_name || staging_record.class.table_name
  when ActiveRecord::Base
    id = staging_record.id
    table_name = staging_record.class.table_name
  else
    id = staging_record
    table_name = options[:table_name]
  end

  raise 'Invalid input' unless table_name && id

  return [table_name, id]
end