Module: Dcmgr::Models::ArchiveChangedColumn::InstanceMethods

Defined in:
lib/dcmgr/models/base_new.rb

Instance Method Summary collapse

Instance Method Details

#before_createObject



368
369
370
371
372
# File 'lib/dcmgr/models/base_new.rb', line 368

def before_create
  return false if super == false
  store_changes(self.columns)
  true
end

#before_updateObject



374
375
376
377
378
# File 'lib/dcmgr/models/base_new.rb', line 374

def before_update
  return false if super == false
  store_changes(self.changed_columns)
  true
end

#history_snapshot(at) ⇒ Object

Raises:

  • (TypeError)


342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'lib/dcmgr/models/base_new.rb', line 342

def history_snapshot(at)
  raise TypeError unless at.is_a?(Time)

  if self.created_at > at || (!self.terminated_at.nil? && self.terminated_at < at)
    raise "#{at} is not in the range of the object's life span."
  end
  
  ss = self.dup
  #  SELECT * FROM (SELECT * FROM `instance_histories` WHERE
  #  (`uuid` = 'i-ezsrs132') AND created_at <= '2010-11-30 23:08:05'
  #  ORDER BY created_at DESC) AS a GROUP BY a.attr;
  ds = self.class.history_dataset.filter('uuid=? AND created_at <= ?', self.canonical_uuid, at).order(:created_at.desc)
  ds = ds.from_self.group_by(:attr)
  ds.all.each { |h|
    if !h[:blob_value].nil?
      ss.send("#{h[:attr]}=", typecast_value(h[:attr], h[:blob_value]))
    else
      ss.send("#{h[:attr]}=", typecast_value(h[:attr], h[:vchar_value]))
    end
  }
  # take care for serialized columns by serialization plugin.
  ss.deserialized_values.clear if ss.respond_to?(:deserialized_values)
  
  ss
end