Module: Versionable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/versionable/version.rb,
lib/versionable/plugins/versionable.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- VERSION =
'0.2.9'
Instance Method Summary collapse
- #save(options = {}) ⇒ Object
- #save_version(updater_id = nil) ⇒ Object
- #update_attributes(attrs = {}) ⇒ Object
Instance Method Details
#save(options = {}) ⇒ Object
12 13 14 15 16 |
# File 'lib/versionable/plugins/versionable.rb', line 12 def save(={}) updater_id = .delete(:updater_id) save_version(updater_id) if self.respond_to?(:rolling_back) && !rolling_back super end |
#save_version(updater_id = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/versionable/plugins/versionable.rb', line 18 def save_version(updater_id=nil) if self.respond_to?(:versions) version = self.current_version version. = self. if self.versions.empty? version.pos = 0 else version.pos = self.versions.last.pos + 1 end if self.version_at(self.version_number).try(:data) != version.data version.updater_id = updater_id version.save self.versions.shift if self.versions.count >= @limit self.versions << version self.version_number = version.pos if @versions_count @versions_count = @versions_count + 1 else @versions_count = Version.count(:doc_id => self._id.to_s) end end end end |
#update_attributes(attrs = {}) ⇒ Object
6 7 8 9 10 |
# File 'lib/versionable/plugins/versionable.rb', line 6 def update_attributes(attrs={}) updater_id = attrs.delete(:updater_id) self.attributes = attrs save(:updater_id => updater_id) end |