Module: DataMapper::Is::Revisioned::InstanceMethods
- Defined in:
- lib/dm-is-revisioned/is/revisioned.rb
Instance Method Summary collapse
- #check_if_wants_new_version ⇒ Object
-
#pending_version_attributes ⇒ Hash
Returns a hash of original values to be stored in the versions table when a new version is created.
- #save_new_version(result, *args) ⇒ Object
- #versioned_attribute_changed? ⇒ Boolean (also: #wants_new_version?)
-
#versions(include_current = false) ⇒ Collection
Returns a collection of other versions of this resource.
Instance Method Details
#check_if_wants_new_version ⇒ Object
129 130 131 |
# File 'lib/dm-is-revisioned/is/revisioned.rb', line 129 def check_if_wants_new_version @should_save_version = wants_new_version? end |
#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.
–
104 105 106 |
# File 'lib/dm-is-revisioned/is/revisioned.rb', line 104 def pending_version_attributes @pending_version_attributes ||= {} end |
#save_new_version(result, *args) ⇒ Object
133 134 135 136 137 138 |
# File 'lib/dm-is-revisioned/is/revisioned.rb', line 133 def save_new_version(result, *args) if result && @should_save_version self.class::Version.create(self.attributes) @should_save_version = false end end |
#versioned_attribute_changed? ⇒ Boolean Also known as: wants_new_version?
123 124 125 |
# File 'lib/dm-is-revisioned/is/revisioned.rb', line 123 def versioned_attribute_changed? dirty_attributes.has_key?(self.class.properties[self.class.versioned_property_name]) end |
#versions(include_current = false) ⇒ Collection
Returns a collection of other versions of this resource. The versions are related on the models keys, and ordered by the version field.
–
115 116 117 118 119 120 121 |
# File 'lib/dm-is-revisioned/is/revisioned.rb', line 115 def versions(include_current = false) query = {} version = self.class.const_get("Version") self.class.key.zip(self.key) { |property, value| query[property.name] = value } query.merge(:order => version.key.collect { |key| key.name.desc }) result = version.all(query) end |