Module: Glue::Revisable::Mixin

Defined in:
lib/glue/revisable.rb

Overview

This mixin is injected into the dynamically generated Revision class. You can customize this in your application to store extra fields per revision.

Instance Method Summary collapse

Instance Method Details

#initialize(obj, options = {}) ⇒ Object

Override to handle your options.



40
41
42
43
# File 'lib/glue/revisable.rb', line 40

def initialize(obj, options = {})
  revision_from(obj)
  @create_time = Time.now
end

#revision_from(obj) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/glue/revisable.rb', line 45

def revision_from(obj)
  for prop in obj.class.properties.values
    # gmosx, FIXME: test against primary key, not oid.
    unless prop.symbol == :oid
      instance_variable_set "@#{prop}", obj.send(prop.to_s) 
    end
  end
end

#revision_to(obj) ⇒ Object Also known as: apply_to



54
55
56
57
58
59
60
61
# File 'lib/glue/revisable.rb', line 54

def revision_to(obj)
  for prop in obj.class.properties.values
    # gmosx, FIXME: test against primary key, not oid.
    unless prop.symbol == :oid
      obj.instance_variable_set "@#{prop}", self.send(prop.to_s) 
    end
  end
end