Class: Version

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/version.rb

Overview

A Version represents a numbered revision of an ActiveRecord model.

The version has two attributes number and yaml where the yaml attribute holds the representation of the ActiveRecord model attributes. To access these call model which will return an instantiated model of the original class with those attributes.

Instance Method Summary collapse

Instance Method Details

#modelObject

Return an instance of the versioned ActiveRecord model with the attribute values of this version.



20
21
22
23
24
25
26
# File 'lib/version.rb', line 20

def model
  obj = versionable.class.new
  YAML::load( self.yaml ).each do |var_name,var_value|
    obj.__send__( "#{var_name}=", var_value )
  end
  obj
end

#nextObject

Return the next higher numbered version, or nil if this is the last version



29
30
31
# File 'lib/version.rb', line 29

def next
  versionable.versions.next_version( self.number )
end

#previousObject

Return the next lower numbered version, or nil if this is the first version



34
35
36
# File 'lib/version.rb', line 34

def previous
  versionable.versions.previous_version( self.number )
end