Class: ActiveSnapshot::SnapshotItem

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/active_snapshot/models/snapshot_item.rb

Instance Method Summary collapse

Instance Method Details

#objectObject



16
17
18
19
20
21
22
23
24
# File 'lib/active_snapshot/models/snapshot_item.rb', line 16

def object
  yaml_method = "unsafe_load"

  if !YAML.respond_to?("unsafe_load")
    yaml_method = "load"
  end

  @metadata ||= YAML.send(yaml_method, self[:object]).with_indifferent_access
end

#object=(h) ⇒ Object



26
27
28
29
# File 'lib/active_snapshot/models/snapshot_item.rb', line 26

def object=(h)
  @object = nil
  self[:object] = YAML.dump(h)
end

#restore_item!Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/active_snapshot/models/snapshot_item.rb', line 31

def restore_item!
  ### Add any custom logic here
  
  if !item
    item_klass = item_type.constantize

    self.item = item_klass.new
  end

  item.assign_attributes(object)

  item.save!(validate: false, touch: false)
end