module Snaps
Constants
- VERSION
Public Class Methods
revision(options={})
click to toggle source
# File lib/snaps.rb, line 5 def self.revision(options={}) Module.new do extend ActiveSupport::Concern included do before_save :ensure_perma_id if options[:default_tag] after_create do snaps_tag!(options[:default_tag]) end end end def snapshot!(options = {}, &block) Snapshot.create(self, options.merge(self.class.snaps_options), &block) end def snaps_tag!(tag) Tag.create!( record: self, tag: tag ) end def snaps_untag!(tag) Tag .for_all_revisions_of(self) .with_name(tag) .supersede! end def snaps_revisions self.class.where(perma_id: perma_id) end def ensure_perma_id self.perma_id ||= (self.class.maximum(:perma_id) || 0) + 1 end class_methods do def with_snaps_tag(tag, options={}) if options[:all_revisions] Tag.all_revisions_with_tag(self, tag) else Tag.current_revisions_with_tag(self, tag) end end def without_snaps_tag(tag, options={}) Tag.all_revisions_without_tag(self, tag) end define_method :snaps_options do options end end end end
Public Instance Methods
ensure_perma_id()
click to toggle source
# File lib/snaps.rb, line 42 def ensure_perma_id self.perma_id ||= (self.class.maximum(:perma_id) || 0) + 1 end
snaps_revisions()
click to toggle source
# File lib/snaps.rb, line 38 def snaps_revisions self.class.where(perma_id: perma_id) end
snaps_tag!(tag)
click to toggle source
# File lib/snaps.rb, line 24 def snaps_tag!(tag) Tag.create!( record: self, tag: tag ) end
snaps_untag!(tag)
click to toggle source
# File lib/snaps.rb, line 31 def snaps_untag!(tag) Tag .for_all_revisions_of(self) .with_name(tag) .supersede! end
snapshot!(options = {}, &block)
click to toggle source
# File lib/snaps.rb, line 18 def snapshot!(options = {}, &block) Snapshot.create(self, options.merge(self.class.snaps_options), &block) end
with_snaps_tag(tag, options={})
click to toggle source
# File lib/snaps.rb, line 47 def with_snaps_tag(tag, options={}) if options[:all_revisions] Tag.all_revisions_with_tag(self, tag) else Tag.current_revisions_with_tag(self, tag) end end
without_snaps_tag(tag, options={})
click to toggle source
# File lib/snaps.rb, line 55 def without_snaps_tag(tag, options={}) Tag.all_revisions_without_tag(self, tag) end