Module: DataMapper::Is::Revisioned::InstanceMethods

Defined in:
lib/dm-is-revisioned/is/revisioned.rb

Instance Method Summary collapse

Instance Method Details

#check_if_wants_new_versionObject



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_attributesHash

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.

Returns:

  • (Hash)


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?

Returns:

  • (Boolean)


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.

Returns:

  • (Collection)


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