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

- old
+ new

@@ -5,11 +5,18 @@ def self.included(base) base.extend ClassMethods end module ClassMethods - def versioned + def versioned(options = {}) + class_inheritable_accessor :versioned_columns + self.versioned_columns = case + when options[:only] then column_names & Array(options[:only]).map(&:to_s) + when options[:except] then column_names - Array(options[:except]).map(&:to_s) + else 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,11 +58,11 @@ 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 @@ -64,10 +71,10 @@ def create_initial_version versions.create(:changes => nil, :number => 1) end def create_version - versions.create(:changes => changes, :number => (last_version + 1)) + versions.create(:changes => changes.slice(*versioned_columns), :number => (last_version + 1)) reset_version end public def version