Browse files

remove change tracking module, since it's somewhere else now

  • Loading branch information...
1 parent e091b9b commit 07c6fac8d5a72d021b1e5f7c3dac4ee4bef738da @jamesgolick committed Jan 3, 2010
Showing with 0 additions and 157 deletions.
  1. +0 −1 lib/friendly.rb
  2. +0 −91 lib/friendly/change_tracking.rb
  3. +0 −65 spec/unit/change_tracking_spec.rb
View
1 lib/friendly.rb
@@ -3,7 +3,6 @@
require 'friendly/boolean'
require 'friendly/cache'
require 'friendly/cache/by_id'
-require 'friendly/change_tracking'
require 'friendly/config'
require 'friendly/data_store'
require 'friendly/document'
View
91 lib/friendly/change_tracking.rb
@@ -1,91 +0,0 @@
-require 'set'
-
-module Friendly
- # Provides attr accessors that track changes.
- #
- module ChangeTracking
- def self.included(klass)
- klass.send(:extend, ClassMethods)
- end
-
- module ClassMethods
- # Create a change tracking accessor.
- #
- # e.g.
- # class Person
- # include Friendly::ChangeTracking
- #
- # change_tracking_accessor :name
- # end
- #
- # This macro provides 5 methods for each accessor. Using :name as
- # an example, they are:
- #
- # name= Set the name instance variable, keeping track
- # of the original value.
- # name Get the current value of name.
- # name_will_change Record the current value of name and indicate
- # that it has changed. Used internally and useful
- # if you need to set the value of an instance variable
- # manually.
- # name_changed? Returns true or false based on whether the value has
- # changed since instantiation or last reset.
- # name_was The value of the variable before the last change.
- #
- def change_tracking_accessor(*names)
- names.each do |n|
- class_eval do
- eval <<-__END__
- def #{n}=(value) # def name=(value)
- #{n}_will_change # name_will_change
- @#{n} = value # @name = value
- end # end
-
- def #{n} # def name
- @#{n} # @name
- end # end
-
- def #{n}_will_change # def name_will_change
- changed << :#{n} # changed << :name
- @#{n}_was = @#{n} # @name_was = @name
- end # end
-
- def #{n}_changed? # def named_changed?
- changed.include?(:#{n}) # changed.include?(:name)
- end # end
-
- def #{n}_was # def name_was?
- @#{n}_was # @name_was
- end # end
- __END__
- end
- end
- end
- end
-
- # Have any of the attributes that are being tracked changed since last reset?
- #
- def changed?
- !changed.empty?
- end
-
- # Which attributes that are being tracked have changed since last reset?
- #
- def changed
- @changed ||= Set.new
- end
-
- # Reset all the changes to this object.
- #
- def reset_changes
- changed.each { |c| not_changed(c) }
- end
-
- # Reset the changed-ness of one attribute.
- #
- def not_changed(attribute)
- instance_variable_set(:"@#{attribute}_was", nil)
- changed.delete(attribute)
- end
- end
-end
View
65 spec/unit/change_tracking_spec.rb
@@ -1,65 +0,0 @@
-require File.expand_path("../../spec_helper", __FILE__)
-
-describe "Friendly::ChangeTracking" do
- before do
- @klass = Class.new do
- include Friendly::ChangeTracking
-
- change_tracking_accessor :some_variable
- end
-
- @object = @klass.new
- end
-
- describe "setting a variable" do
- before do
- @object.instance_variable_set(:@some_variable, "the old value")
- @object.some_variable = "a value"
- end
-
- it "sets the instance variable" do
- @object.instance_variable_get(:@some_variable).should == "a value"
- end
-
- it "marks the variable as changed" do
- @object.should be_some_variable_changed
- end
-
- it "saves the old value of the variable" do
- @object.some_variable_was.should == "the old value"
- end
-
- it "reports the object as dirty" do
- @object.should be_changed
- end
- end
-
- describe "resetting changes" do
- before do
- @object.some_variable = "whatever"
- @object.reset_changes
- end
-
- it "resets the changed status of the variable" do
- @object.should_not be_some_variable_changed
- end
-
- it "resets the changed status of the object" do
- @object.should_not be_changed
- end
-
- it "returns nil for variable_was" do
- @object.some_variable_was.should be_nil
- end
- end
-
- describe "getting a variable" do
- before do
- @object.some_variable = "whatever"
- end
-
- it "returns the current value of the attr" do
- @object.some_variable.should == "whatever"
- end
- end
-end

0 comments on commit 07c6fac

Please sign in to comment.