Class: Clowne::Adapters::Sequel::RecordWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/clowne/adapters/sequel/record_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_storeObject (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

#recordObject (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_hashObject



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_modelObject



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