Class: Hash

Inherits:
Object show all
Defined in:
lib/odb.rb

Instance Method Summary collapse

Instance Method Details

#__deserialize__(db = ODB::Database.current) ⇒ Object



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/odb.rb', line 215

def __deserialize__(db = ODB::Database.current)
  object = self[:value] ? self[:value] : self[:class].allocate
  self[:ivars].each do |ivar, value|
    object.instance_variable_set("@#{ivar}", Hash === value ? value[:value] : db.store[value])
  end
  case self[:type]
  when :array
    object.replace(self[:list].map {|item| db.store[item] })
  when :hash
    self[:list].each do |values|
      object[db.store[values[0]]] = object[db.store[values[1]]]
    end
  end
  object
end

#__serialize__(transaction = ODB::Transaction.current) ⇒ Object



205
206
207
208
209
210
211
212
213
# File 'lib/odb.rb', line 205

def __serialize__(transaction = ODB::Transaction.current)
  obj = super
  obj[:type] = :hash
  obj[:items] = map do |k, v|
    transaction.objects.push(k.object_id, v.object_id)
    [k.object_id, v.object_id]
  end
  obj
end