dirty_hashy 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +7 -0
- data/README.textile +29 -20
- data/VERSION +1 -1
- data/dirty_hashy.gemspec +1 -1
- data/lib/dirty.rb +2 -0
- data/lib/dirty/attributes.rb +39 -0
- data/lib/dirty/hash.rb +108 -0
- data/lib/dirty_hashy.rb +4 -84
- data/lib/dirty_hashy/version.rb +3 -3
- data/lib/dirty_indifferent_hashy.rb +5 -0
- data/test/unit/dirty/test_attributes.rb +176 -0
- data/test/unit/test_dirty_hashy.rb +109 -94
- data/test/unit/test_dirty_indifferent_hashy.rb +500 -0
- metadata +47 -35
- data/lib/dirty_attributes.rb +0 -37
- data/test/unit/test_dirty_attributes.rb +0 -174
metadata
CHANGED
@@ -1,35 +1,39 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: dirty_hashy
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.3
|
3
|
+
version: !ruby/object:Gem::Version
|
5
4
|
prerelease:
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Paul Engel
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
|
13
|
+
date: 2012-01-04 00:00:00 +01:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
15
17
|
name: activesupport
|
16
|
-
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
20
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
21
24
|
version: 3.0.0
|
22
25
|
type: :runtime
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
is expected to be!
|
27
|
-
email:
|
26
|
+
version_requirements: *id001
|
27
|
+
description: Dirty tracking within hashes with indifferent access or objects as it is expected to be!
|
28
|
+
email:
|
28
29
|
- paul.engel@holder.nl
|
29
30
|
executables: []
|
31
|
+
|
30
32
|
extensions: []
|
33
|
+
|
31
34
|
extra_rdoc_files: []
|
32
|
-
|
35
|
+
|
36
|
+
files:
|
33
37
|
- .gitignore
|
34
38
|
- CHANGELOG.rdoc
|
35
39
|
- Gemfile
|
@@ -38,40 +42,48 @@ files:
|
|
38
42
|
- Rakefile
|
39
43
|
- VERSION
|
40
44
|
- dirty_hashy.gemspec
|
41
|
-
- lib/
|
45
|
+
- lib/dirty.rb
|
46
|
+
- lib/dirty/attributes.rb
|
47
|
+
- lib/dirty/hash.rb
|
42
48
|
- lib/dirty_hashy.rb
|
43
49
|
- lib/dirty_hashy/version.rb
|
50
|
+
- lib/dirty_indifferent_hashy.rb
|
44
51
|
- lib/method_map.rb
|
45
52
|
- script/console
|
46
53
|
- test/test_helper.rb
|
47
|
-
- test/unit/
|
54
|
+
- test/unit/dirty/test_attributes.rb
|
48
55
|
- test/unit/test_dirty_hashy.rb
|
56
|
+
- test/unit/test_dirty_indifferent_hashy.rb
|
57
|
+
has_rdoc: true
|
49
58
|
homepage: https://github.com/archan937/dirty_hashy
|
50
59
|
licenses: []
|
60
|
+
|
51
61
|
post_install_message:
|
52
62
|
rdoc_options: []
|
53
|
-
|
63
|
+
|
64
|
+
require_paths:
|
54
65
|
- lib
|
55
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
67
|
none: false
|
57
|
-
requirements:
|
58
|
-
- -
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version:
|
61
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
73
|
none: false
|
63
|
-
requirements:
|
64
|
-
- -
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version:
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
67
78
|
requirements: []
|
79
|
+
|
68
80
|
rubyforge_project:
|
69
|
-
rubygems_version: 1.
|
81
|
+
rubygems_version: 1.6.2
|
70
82
|
signing_key:
|
71
83
|
specification_version: 3
|
72
|
-
summary: Dirty tracking within hashes with indifferent access or objects as it is
|
73
|
-
|
74
|
-
test_files:
|
84
|
+
summary: Dirty tracking within hashes with indifferent access or objects as it is expected to be!
|
85
|
+
test_files:
|
75
86
|
- test/test_helper.rb
|
76
|
-
- test/unit/
|
87
|
+
- test/unit/dirty/test_attributes.rb
|
77
88
|
- test/unit/test_dirty_hashy.rb
|
89
|
+
- test/unit/test_dirty_indifferent_hashy.rb
|
data/lib/dirty_attributes.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
module DirtyAttributes
|
2
|
-
|
3
|
-
def self.included(base)
|
4
|
-
base.extend ClassMethods
|
5
|
-
base.send :include, InstanceMethods
|
6
|
-
base.send :include, MethodMap
|
7
|
-
end
|
8
|
-
|
9
|
-
module ClassMethods
|
10
|
-
def attrs(*names)
|
11
|
-
@attrs = names.collect(&:to_s)
|
12
|
-
end
|
13
|
-
|
14
|
-
def attributes
|
15
|
-
@attrs
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
module InstanceMethods
|
20
|
-
attr_reader :attributes
|
21
|
-
|
22
|
-
def initialize
|
23
|
-
@attributes = DirtyHashy.new({}, true, self.class.attributes).tap do |hashy|
|
24
|
-
dirty_map! hashy
|
25
|
-
clean_up!
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def attributes=(other)
|
30
|
-
attributes.replace other
|
31
|
-
rescue IndexError => e
|
32
|
-
e.message.match /"(.*)"/
|
33
|
-
raise NoMethodError, "undefined method `#{$1}=' for #{self.inspect}"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
@@ -1,174 +0,0 @@
|
|
1
|
-
require File.expand_path("../../test_helper", __FILE__)
|
2
|
-
|
3
|
-
module Unit
|
4
|
-
class TestDirtyAttributes < MiniTest::Unit::TestCase
|
5
|
-
|
6
|
-
describe DirtyAttributes do
|
7
|
-
it "should behave as expected without key restriction" do
|
8
|
-
class Person
|
9
|
-
include DirtyAttributes
|
10
|
-
end
|
11
|
-
|
12
|
-
person = Person.new
|
13
|
-
|
14
|
-
assert_equal({}, person.attributes)
|
15
|
-
assert_equal false, person.dirty?
|
16
|
-
assert_equal false, person.changed?
|
17
|
-
assert_equal({}, person.changes)
|
18
|
-
|
19
|
-
assert_raises(NoMethodError) do
|
20
|
-
person.name
|
21
|
-
end
|
22
|
-
|
23
|
-
person.name = "Paul"
|
24
|
-
|
25
|
-
assert_equal "Paul", person.name
|
26
|
-
assert_equal true, person.dirty?
|
27
|
-
assert_equal true, person.changed?
|
28
|
-
assert_equal true, person.name_changed?
|
29
|
-
assert_equal [nil, "Paul"], person.name_change
|
30
|
-
assert_equal({"name" => [nil, "Paul"]}, person.changes)
|
31
|
-
|
32
|
-
person.name = nil
|
33
|
-
|
34
|
-
assert_equal false, person.dirty?
|
35
|
-
assert_equal false, person.changed?
|
36
|
-
assert_equal false, person.name_changed?
|
37
|
-
assert_equal nil, person.name_change
|
38
|
-
assert_equal({}, person.changes)
|
39
|
-
|
40
|
-
person.name = "Stephan"
|
41
|
-
|
42
|
-
assert_equal true, person.dirty?
|
43
|
-
assert_equal true, person.changed?
|
44
|
-
assert_equal true, person.name_changed?
|
45
|
-
assert_equal [nil, "Stephan"], person.name_change
|
46
|
-
assert_equal({"name" => [nil, "Stephan"]}, person.changes)
|
47
|
-
|
48
|
-
person.clean_up!
|
49
|
-
|
50
|
-
assert_equal false, person.dirty?
|
51
|
-
assert_equal false, person.changed?
|
52
|
-
assert_equal false, person.name_changed?
|
53
|
-
assert_equal nil, person.name_change
|
54
|
-
assert_equal({}, person.changes)
|
55
|
-
|
56
|
-
person.foo = "Bar"
|
57
|
-
|
58
|
-
assert_equal "Bar", person.foo
|
59
|
-
assert_equal true, person.dirty?
|
60
|
-
assert_equal true, person.changed?
|
61
|
-
assert_equal false, person.name_changed?
|
62
|
-
assert_equal true, person.foo_changed?
|
63
|
-
assert_equal nil, person.name_change
|
64
|
-
assert_equal [nil, "Bar"], person.foo_change
|
65
|
-
assert_equal({"foo" => [nil, "Bar"]}, person.changes)
|
66
|
-
|
67
|
-
person.attributes.merge! :company => "Internetbureau Holder B.V."
|
68
|
-
|
69
|
-
assert_equal true, person.dirty?
|
70
|
-
assert_equal true, person.changed?
|
71
|
-
assert_equal false, person.name_changed?
|
72
|
-
assert_equal true, person.foo_changed?
|
73
|
-
assert_equal true, person.company_changed?
|
74
|
-
assert_equal nil, person.name_change
|
75
|
-
assert_equal [nil, "Bar"], person.foo_change
|
76
|
-
assert_equal [nil, "Internetbureau Holder B.V."], person.company_change
|
77
|
-
assert_equal({"foo" => [nil, "Bar"], "company" => [nil, "Internetbureau Holder B.V."]}, person.changes)
|
78
|
-
|
79
|
-
person.attributes.delete :foo
|
80
|
-
person.clean_up!
|
81
|
-
|
82
|
-
assert_equal false, person.dirty?
|
83
|
-
assert_equal false, person.changed?
|
84
|
-
assert_equal({"name" => "Stephan", "company" => "Internetbureau Holder B.V."}, person.attributes)
|
85
|
-
assert_equal({}, person.changes)
|
86
|
-
|
87
|
-
person.attributes = {"name" => "Paul", "city" => "Amsterdam"}
|
88
|
-
|
89
|
-
assert_equal true, person.dirty?
|
90
|
-
assert_equal true, person.changed?
|
91
|
-
assert_equal true, person.name_changed?
|
92
|
-
assert_equal true, person.company_changed?
|
93
|
-
assert_equal true, person.city_changed?
|
94
|
-
assert_equal ["Stephan", "Paul"], person.name_change
|
95
|
-
assert_equal ["Internetbureau Holder B.V.", nil], person.company_change
|
96
|
-
assert_equal [nil, "Amsterdam"], person.city_change
|
97
|
-
assert_equal({"name" => ["Stephan", "Paul"], "company" => ["Internetbureau Holder B.V.", nil], "city" => [nil, "Amsterdam"]}, person.changes)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should behave as expected with key restriction" do
|
101
|
-
class User
|
102
|
-
include DirtyAttributes
|
103
|
-
attrs :name
|
104
|
-
end
|
105
|
-
|
106
|
-
user = User.new
|
107
|
-
|
108
|
-
assert_equal({"name" => nil}, user.attributes)
|
109
|
-
assert_equal nil, user.name
|
110
|
-
assert_equal false, user.dirty?
|
111
|
-
assert_equal false, user.changed?
|
112
|
-
assert_equal({}, user.changes)
|
113
|
-
|
114
|
-
assert_raises(NoMethodError) do
|
115
|
-
user.foo
|
116
|
-
end
|
117
|
-
|
118
|
-
assert_raises(NoMethodError) do
|
119
|
-
user.foo = "Bar"
|
120
|
-
end
|
121
|
-
|
122
|
-
user.name = "Paul"
|
123
|
-
|
124
|
-
assert_equal "Paul", user.name
|
125
|
-
assert_equal true, user.dirty?
|
126
|
-
assert_equal true, user.changed?
|
127
|
-
assert_equal true, user.name_changed?
|
128
|
-
assert_equal [nil, "Paul"], user.name_change
|
129
|
-
assert_equal({"name" => [nil, "Paul"]}, user.changes)
|
130
|
-
|
131
|
-
user.name = nil
|
132
|
-
|
133
|
-
assert_equal false, user.dirty?
|
134
|
-
assert_equal false, user.changed?
|
135
|
-
assert_equal false, user.name_changed?
|
136
|
-
assert_equal nil, user.name_change
|
137
|
-
assert_equal({}, user.changes)
|
138
|
-
|
139
|
-
user.name = "Stephan"
|
140
|
-
|
141
|
-
assert_equal true, user.dirty?
|
142
|
-
assert_equal true, user.changed?
|
143
|
-
assert_equal true, user.name_changed?
|
144
|
-
assert_equal [nil, "Stephan"], user.name_change
|
145
|
-
assert_equal({"name" => [nil, "Stephan"]}, user.changes)
|
146
|
-
|
147
|
-
user.clean_up!
|
148
|
-
|
149
|
-
assert_equal false, user.dirty?
|
150
|
-
assert_equal false, user.changed?
|
151
|
-
assert_equal false, user.name_changed?
|
152
|
-
assert_equal nil, user.name_change
|
153
|
-
assert_equal({}, user.changes)
|
154
|
-
|
155
|
-
user.attributes = {"name" => "Paul"}
|
156
|
-
|
157
|
-
assert_equal true, user.dirty?
|
158
|
-
assert_equal true, user.changed?
|
159
|
-
assert_equal true, user.name_changed?
|
160
|
-
assert_equal ["Stephan", "Paul"], user.name_change
|
161
|
-
assert_equal({"name" => ["Stephan", "Paul"]}, user.changes)
|
162
|
-
|
163
|
-
assert_raises(NoMethodError) do
|
164
|
-
user.attributes = {"company" => "Internetbureau Holder B.V."}
|
165
|
-
end
|
166
|
-
|
167
|
-
assert_raises(IndexError) do
|
168
|
-
user.attributes.merge! "company" => "Internetbureau Holder B.V."
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
end
|
174
|
-
end
|