find first version after the given version.
# File lib/annotations_version_fu.rb, line 46 46: def self.after(version) 47: find :first, :order => 'version', 48: :conditions => ["#{original_class.versioned_foreign_key} = ? and version > ?", version.send(original_class.versioned_foreign_key), version.version] 49: end
find first version before the given version
# File lib/annotations_version_fu.rb, line 40 40: def self.before(version) 41: find :first, :order => 'version desc', 42: :conditions => ["#{original_class.versioned_foreign_key} = ? and version < ?", version.send(original_class.versioned_foreign_key), version.version] 43: end
(Not documented)
# File lib/annotations_version_fu.rb, line 12 12: def annotations_version_fu(options={}, &block) 13: return if self.included_modules.include? AnnotationsVersionFu::InstanceMethods 14: __send__ :include, AnnotationsVersionFu::InstanceMethods 15: 16: cattr_accessor :versioned_class_name, :versioned_foreign_key, :versioned_table_name, 17: :version_column, :versioned_columns 18: 19: self.versioned_class_name = options[:class_name] || 'Version' 20: self.versioned_foreign_key = options[:foreign_key] || self.to_s.foreign_key 21: self.versioned_table_name = options[:table_name] || "#{table_name_prefix}#{base_class.name.demodulize.underscore}_versions#{table_name_suffix}" 22: self.version_column = options[:version_column] || 'version' 23: 24: # Setup versions association 25: class_eval do 26: has_many :versions, :class_name => "#{self.to_s}::#{versioned_class_name}", 27: :foreign_key => versioned_foreign_key, 28: :dependent => :destroy do 29: def latest 30: find :first, :order=>'version desc' 31: end 32: end 33: 34: before_save :check_for_new_version 35: end 36: 37: # Versioned Model 38: const_set(versioned_class_name, Class.new(ActiveRecord::Base)).class_eval do 39: # find first version before the given version 40: def self.before(version) 41: find :first, :order => 'version desc', 42: :conditions => ["#{original_class.versioned_foreign_key} = ? and version < ?", version.send(original_class.versioned_foreign_key), version.version] 43: end 44: 45: # find first version after the given version. 46: def self.after(version) 47: find :first, :order => 'version', 48: :conditions => ["#{original_class.versioned_foreign_key} = ? and version > ?", version.send(original_class.versioned_foreign_key), version.version] 49: end 50: 51: def previous 52: self.class.before(self) 53: end 54: 55: def next 56: self.class.after(self) 57: end 58: end 59: 60: # Housekeeping on versioned class 61: versioned_class.cattr_accessor :original_class 62: versioned_class.original_class = self 63: versioned_class.set_table_name versioned_table_name 64: 65: # Version parent association 66: versioned_class.belongs_to self.to_s.demodulize.underscore.to_sym, 67: :class_name => "::#{self.to_s}", 68: :foreign_key => versioned_foreign_key 69: 70: # Block extension 71: versioned_class.class_eval &block if block_given? 72: 73: # Finally setup which columns to version 74: self.versioned_columns = versioned_class.new.attributes.keys - 75: [versioned_class.primary_key, versioned_foreign_key, version_column, 'created_at', 'updated_at'] 76: end
(Not documented)
# File lib/annotations_version_fu.rb, line 29 29: def latest 30: find :first, :order=>'version desc' 31: end
(Not documented)
# File lib/annotations_version_fu.rb, line 55 55: def next 56: self.class.after(self) 57: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.