Module: DataMapper::Has::Versions::InstanceMethods
- Defined in:
- lib/dm-has-versions/has/versions.rb
Instance Method Summary collapse
-
#pending_version_attributes ⇒ Hash
Returns a hash of original values to be stored in the versions table when a new version is created.
- #revert_to(version) ⇒ Object
- #version ⇒ Object
-
#versions ⇒ Collection
Returns a collection of other versions of this resource.
Instance Method Details
#pending_version_attributes ⇒ Hash
Returns a hash of original values to be stored in the versions table when a new version is created. It is cleared after a version model is created.
–
64 65 66 |
# File 'lib/dm-has-versions/has/versions.rb', line 64 def pending_version_attributes @pending_version_attributes ||= {} end |
#revert_to(version) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/dm-has-versions/has/versions.rb', line 85 def revert_to(version) if target = versions.first(:offset => version) transaction do self.properties.each do |property| next if property.key? name = property.name self.attribute_set(name, target.attribute_get(name)) end pending_version_attributes.clear return false unless save versions.all(:id.gte => target.id).destroy! end end !!target end |
#version ⇒ Object
81 82 83 |
# File 'lib/dm-has-versions/has/versions.rb', line 81 def version versions.size end |
#versions ⇒ Collection
Returns a collection of other versions of this resource. The versions are related on the models keys, and ordered by the version field.
–
75 76 77 78 79 |
# File 'lib/dm-has-versions/has/versions.rb', line 75 def versions version = self.class.const_get("Version") original_key = "#{self.class.storage_name.singular}_id".intern version.all(original_key => self.id, :order => [:id.asc]) end |