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
# File 'lib/glue/revisable.rb', line 45

def revision_from obj
  for a in obj.class.serializable_attributes
    unless a == obj.class.primary_key
      instance_variable_set "@#{a}", obj.send(a.to_s)
    end
  end
end

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



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

def revision_to obj
  for a in obj.class.serializable_attributes
    unless a == obj.class.primary_key
      obj.instance_variable_set "@#{a}", self.send(a.to_s)
    end
  end
end