Class: Sprig::Reap::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/sprig/reap/record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record, model) ⇒ Record

Returns a new instance of Record.



8
9
10
11
# File 'lib/sprig/reap/record.rb', line 8

def initialize(record, model)
  @record = record
  @model  = model
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



3
4
5
# File 'lib/sprig/reap/record.rb', line 3

def model
  @model
end

#recordObject (readonly)

Returns the value of attribute record.



3
4
5
# File 'lib/sprig/reap/record.rb', line 3

def record
  @record
end

#sprig_idObject



23
24
25
# File 'lib/sprig/reap/record.rb', line 23

def sprig_id
  @sprig_id ||= model.existing_sprig_ids.include?(record.id) ? model.generate_sprig_id : record.id
end

Instance Method Details

#attributesObject



13
14
15
# File 'lib/sprig/reap/record.rb', line 13

def attributes
  @attributes ||= model.attributes.delete_if { |a| a == "id" }
end

#to_hashObject



17
18
19
20
21
# File 'lib/sprig/reap/record.rb', line 17

def to_hash
  attributes.reduce({"sprig_id" => sprig_id}) do |hash, attr|
    hash.merge(attr => get_value_for(attr))
  end
end