Class: Clowne::Adapters::Sequel::RecordWrapper
- Inherits:
-
Object
- Object
- Clowne::Adapters::Sequel::RecordWrapper
- Defined in:
- lib/clowne/adapters/sequel/record_wrapper.rb
Instance Attribute Summary collapse
-
#association_store ⇒ Object
readonly
Returns the value of attribute association_store.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
-
#initialize(record) ⇒ RecordWrapper
constructor
A new instance of RecordWrapper.
- #remember_assoc(association, value) ⇒ Object
- #to_hash ⇒ Object
- #to_model ⇒ Object
Constructor Details
#initialize(record) ⇒ RecordWrapper
Returns a new instance of RecordWrapper.
9 10 11 12 |
# File 'lib/clowne/adapters/sequel/record_wrapper.rb', line 9 def initialize(record) @record = record @association_store = {} end |
Instance Attribute Details
#association_store ⇒ Object (readonly)
Returns the value of attribute association_store.
7 8 9 |
# File 'lib/clowne/adapters/sequel/record_wrapper.rb', line 7 def association_store @association_store end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
7 8 9 |
# File 'lib/clowne/adapters/sequel/record_wrapper.rb', line 7 def record @record end |
Instance Method Details
#remember_assoc(association, value) ⇒ Object
14 15 16 |
# File 'lib/clowne/adapters/sequel/record_wrapper.rb', line 14 def remember_assoc(association, value) @association_store[association] = value end |
#to_hash ⇒ Object
24 25 26 27 28 29 |
# File 'lib/clowne/adapters/sequel/record_wrapper.rb', line 24 def to_hash init_hash = record.to_hash association_store.each_with_object(init_hash) do |(name, value), acc| acc[name] = association_to_model(value) end end |
#to_model ⇒ Object
18 19 20 21 22 |
# File 'lib/clowne/adapters/sequel/record_wrapper.rb', line 18 def to_model association_store.each_with_object(record) do |(name, value), acc| acc.send("#{name}=", association_to_model(value)) end end |