lib/vestal_versions.rb in sthapit-vestal_versions-0.7.1 vs lib/vestal_versions.rb in sthapit-vestal_versions-0.8.0

- old
+ new

@@ -5,11 +5,21 @@ def self.included(base) base.extend ClassMethods end module ClassMethods - def versioned + def versioned options = {} + + cattr_accessor :versioned_columns + if options[:only] + self.versioned_columns = Array(options[:only]).map( &:to_s ) + elsif options[:except] + self.versioned_columns = column_names - Array(options[:except]).map( &:to_s ) + else + self.versioned_columns = column_names + end + has_many :versions, :as => :versioned, :order => 'versions.number ASC', :dependent => :delete_all do def between(from, to) from_number, to_number = number_at(from), number_at(to) return [] if from_number.nil? || to_number.nil? condition = (from_number == to_number) ? to_number : Range.new(*[from_number, to_number].sort) @@ -51,10 +61,10 @@ def needs_initial_version? versions.empty? end def needs_version? - !changed.empty? + !(versioned_columns & changed).empty? end def reset_version(new_version = nil) @last_version = nil if new_version.nil? @version = new_version