README.textile in dirty_hashy-0.1.3 vs README.textile in dirty_hashy-0.2.0
- old
+ new
@@ -24,19 +24,27 @@
<pre>
bundle install
</pre>
+h2. DirtyHashy versus DirtyIndifferentHashy
+
+"On request":https://github.com/archan937/dirty_hashy/issues/1 of "@technoweenie":https://twitter.com/technoweenie, I have released DirtyHashy v0.2.0. Previous to this release, the @DirtyHashy@ class inherited from ActiveSupport's @HashWithIndifferentAccess@ *but that has changed*.
+
+As of the @0.2.0@ release, the @DirtyHashy@ class is inherited from the @Hash@ class. So I have introduced @DirtyIndifferentHashy@ which resembles the @DirtyHashy@ class of the @0.1.x@ releases. You can check out the different types of behaviour by looking at the "DirtyHashy test":https://github.com/archan937/dirty_hashy/blob/279da72873a91216dbecadb3a6d53ebae2fd8198/test/unit/test_dirty_hashy.rb and "DirtyIndifferentHashy test":https://github.com/archan937/dirty_hashy/blob/279da72873a91216dbecadb3a6d53ebae2fd8198/test/unit/test_dirty_indifferent_hashy.rb.
+
+*Note*: This README will continue focusing on the usage of the @DirtyIndifferentHashy@ class and @Dirty::Attributes@ module.
+
h2. Usage
-Using @DirtyHashy@ is pretty straightforward and can be used as follows:
+Using @DirtyIndifferentHashy@ is pretty straightforward and can be used as follows:
<pre>
require "rubygems"
require "dirty_hashy"
- h = DirtyHashy.new
+ h = DirtyIndifferentHashy.new
h.dirty? #=> false
h[:name] = "Paul"
h.dirty? #=> true
h.changed? :name #=> true
h.was :name #=> nil
@@ -62,21 +70,21 @@
h.dirty? #=> true
h.was :company #=> "Internetbureau Holder B.V."
h.change :company #=> ["Internetbureau Holder B.V.", nil]
</pre>
-h3. Method mapping DirtyHashy
+h3. Method mapping DirtyIndifferentHashy
-You can map methods within a DirtyHashy in order to provide convenience methods like @name@, @name=@, @name_changed?@, @name_was@ and @name_change@. Just pass @true@ for the @map_methods@ argument when initializing a DirtyHashy:
+You can map methods within a DirtyIndifferentHashy in order to provide convenience methods like @name@, @name=@, @name_changed?@, @name_was@ and @name_change@. Just pass @true@ for the @map_methods@ argument when initializing a DirtyIndifferentHashy:
<pre>
require "rubygems"
require "dirty_hashy"
- h = DirtyHashy.new({}, true)
+ h = DirtyIndifferentHashy.new({}, true)
h.dirty? #=> false
- h.name #=> NoMethodError: undefined method `name' for {}:DirtyHashy
+ h.name #=> NoMethodError: undefined method `name' for {}:DirtyIndifferentHashy
h.name = "Paul"
h.dirty? #=> true
h.name_changed? #=> true
h.name_was #=> nil
h.name_change #=> [nil, "Paul"]
@@ -90,19 +98,19 @@
h.name_change #=> ["Paul", "Engel"]
h.foo = "bar"
h.changes #=> {"name"=>["Paul", "Engel"], "foo"=>[nil, "bar"]}
</pre>
-h3. Method mapping DirtyHashy with key restriction
+h3. Method mapping DirtyIndifferentHashy with key restriction
-Along with providing convenience methods, you can also restrict the range of keys you are permitted to read / write / merge / replace of a DirtyHash:
+Along with providing convenience methods, you can also restrict the range of keys you are permitted to read / write / merge / replace of a DirtyIndifferentHashy:
<pre>
require "rubygems"
require "dirty_hashy"
- h = DirtyHashy.new({}, true, [:name])
+ h = DirtyIndifferentHashy.new({}, true, [:name])
h.dirty? #=> false
h.name #=> nil
h.name = "Paul"
h.dirty? #=> true
h.name_changed? #=> true
@@ -110,25 +118,25 @@
h.name_change #=> [nil, "Paul"]
h.merge! :name => "Engel"
h.name #=> "Engel"
h.name_was #=> nil
h.name_change #=> [nil, "Engel"]
- h.foo #=> NoMethodError: undefined method `foo' for {"name"=>"Engel"}:DirtyHashy
- h.foo = "bar" #=> NoMethodError: undefined method `foo=' for {"name"=>"Engel"}:DirtyHashy
+ h.foo #=> NoMethodError: undefined method `foo' for {"name"=>"Engel"}:DirtyIndifferentHashy
+ h.foo = "bar" #=> NoMethodError: undefined method `foo=' for {"name"=>"Engel"}:DirtyIndifferentHashy
h.clean_up!
h.replace :name => "Paul"
h.changes #=> {"name"=>["Engel", "Paul"]}
</pre>
h3. Dirty tracking objects (models)
-Like "ActiveModel::Dirty":http://api.rubyonrails.org/classes/ActiveModel/Dirty.html, you can use "DirtyAttributes":https://github.com/archan937/dirty_hashy/blob/master/lib/dirty_attributes.rb to dirty track your own objects (models). But there are two differences:
+Like "ActiveModel::Dirty":http://api.rubyonrails.org/classes/ActiveModel/Dirty.html, you can use "Dirty::Attributes":https://github.com/archan937/dirty_hashy/blob/master/lib/dirty_attributes.rb to dirty track your own objects (models). But there are two differences:
-# Setting up @DirtyAttributes@ is easier to setup than @ActiveModel::Dirty@
-# The implementation of "DirtyAttributes":https://github.com/archan937/dirty_hashy/tree/master/lib is more minimalistic and thus looks a bit cleaner than "ActiveModel::Dirty":https://github.com/rails/rails/blob/master/activemodel/lib/active_model/dirty.rb with "ActiveModel::AttributeMethods":https://github.com/rails/rails/blob/master/activemodel/lib/active_model/attribute_methods.rb
+# Setting up @Dirty::Attributes@ is easier to setup than @ActiveModel::Dirty@
+# The implementation of "Dirty::Attributes":https://github.com/archan937/dirty_hashy/tree/master/lib is more minimalistic and thus looks a bit cleaner than "ActiveModel::Dirty":https://github.com/rails/rails/blob/master/activemodel/lib/active_model/dirty.rb with "ActiveModel::AttributeMethods":https://github.com/rails/rails/blob/master/activemodel/lib/active_model/attribute_methods.rb
-The following illustrates the differences between @DirtyAttributes@ and @ActiveModel::Dirty@ when implementing a simple @Person@ model:
+The following illustrates the differences between @Dirty::Attributes@ and @ActiveModel::Dirty@ when implementing a simple @Person@ model:
h4. When using ActiveModel::Dirty
<pre>
class Person
@@ -149,15 +157,15 @@
@changed_attributes.clear
end
end
</pre>
-h4. When using DirtyAttributes
+h4. When using Dirty::Attributes
<pre>
class Person
- include DirtyAttributes
+ include Dirty::Attributes
attrs :name
def save
clean_up!
end
@@ -169,11 +177,11 @@
<pre>
require "rubygems"
require "dirty_hashy"
class Person
- include DirtyAttributes
+ include Dirty::Attributes
attrs :name
end
p = Person.new
p.dirty? #=> false
@@ -194,11 +202,11 @@
<pre>
require "rubygems"
require "dirty_hashy"
class Person
- include DirtyAttributes
+ include Dirty::Attributes
end
p = Person.new
p.dirty? #=> false
p.name #=> NoMethodError: undefined method `name' for #<Person:0x00000100d5cd88>
@@ -215,10 +223,11 @@
p.foo #=> "bar"
</pre>
h2. Last remarks
-Please check out "test/unit/test_dirty_hashy.rb":https://github.com/archan937/dirty_hashy/blob/master/test/unit/test_dirty_hashy.rb and "test/unit/test_dirty_attributes.rb":https://github.com/archan937/dirty_hashy/blob/master/test/unit/test_dirty_attributes.rb the tests available. You can run the unit tests with @rake@ within the terminal.
+Please check out "test/unit/test_dirty_hashy.rb":https://github.com/archan937/dirty_hashy/blob/master/test/unit/test_dirty_hashy.rb, "test/unit/test_dirty_indifferent_hashy.rb":https://github.com/archan937/dirty_hashy/blob/master/test/unit/test_dirty_indifferent_hashy.rb and "test/unit/test_dirty_attributes.rb":https://github.com/archan937/dirty_hashy/blob/master/test/unit/test_dirty_attributes.rb the tests available.
+You can run the unit tests with @rake@ within the terminal.
Also, the DirtyHashy repo is provided with @script/console@ which you can use for testing purposes.
Note: *DirtyHashy is successfully tested using Ruby 1.8.7, Ruby 1.9.2 and Ruby 1.9.3*
\ No newline at end of file