Class: Sprig::Reap::Record
- Inherits:
-
Object
- Object
- Sprig::Reap::Record
- Defined in:
- lib/sprig/reap/record.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
- #sprig_id ⇒ Object
Instance Method Summary collapse
- #attributes ⇒ Object
-
#initialize(record, model) ⇒ Record
constructor
A new instance of Record.
- #to_hash ⇒ Object
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
#model ⇒ Object (readonly)
Returns the value of attribute model.
3 4 5 |
# File 'lib/sprig/reap/record.rb', line 3 def model @model end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
3 4 5 |
# File 'lib/sprig/reap/record.rb', line 3 def record @record end |
#sprig_id ⇒ Object
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
#attributes ⇒ Object
13 14 15 |
# File 'lib/sprig/reap/record.rb', line 13 def attributes @attributes ||= model.attributes.delete_if { |a| a == "id" } end |
#to_hash ⇒ Object
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 |