Class: Version
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Version
- 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
-
#model ⇒ Object
Return an instance of the versioned ActiveRecord model with the attribute values of this version.
-
#next ⇒ Object
Return the next higher numbered version, or nil if this is the last version.
-
#previous ⇒ Object
Return the next lower numbered version, or nil if this is the first version.
Instance Method Details
#model ⇒ Object
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 |
#next ⇒ Object
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 |
#previous ⇒ Object
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 |