identifies_as 1.0.5 → 1.0.6

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 CHANGED
@@ -8,3 +8,4 @@ Initial release.
8
8
  Renamed :no_longer_identifying_as! and :instances_no_longer_identify_as! to :stop_identifying_as! and :stop_instances_identifying_as!
9
9
  Added support for subclassing and module inclusion.
10
10
  Added Module-level support for :<, :>, :<=, :>=, :<==>.
11
+ Updates for support to stop identification when an ancestor identifies (either actually or by way of IdentifiesAs).
@@ -49,7 +49,7 @@ module ::IdentifiesAs::ClassInstance
49
49
  # @return [Object] Self.
50
50
  def stop_instances_identifying_as!( *objects )
51
51
 
52
- return ::IdentifiesAs.object_stop_instances_identifying_as!( self, *objects )
52
+ return ::IdentifiesAs.stop_object_instances_identifying_as!( self, *objects )
53
53
 
54
54
  end
55
55
 
@@ -50,7 +50,7 @@ module ::IdentifiesAs::ObjectInstance
50
50
  # @return [Object] Self.
51
51
  def stop_identifying_as!( *objects )
52
52
 
53
- return ::IdentifiesAs.object_stop_identifying_as!( self, *objects )
53
+ return ::IdentifiesAs.stop_object_identifying_as!( self, *objects )
54
54
 
55
55
  end
56
56
 
@@ -9,6 +9,9 @@ module ::IdentifiesAs
9
9
  @identities = { }
10
10
  @instance_identities = { }
11
11
 
12
+ @do_not_identify_as = { }
13
+ @instances_do_not_identify_as = { }
14
+
12
15
  ################################
13
16
  # self.object_identifies_as! #
14
17
  ################################
@@ -26,6 +29,12 @@ module ::IdentifiesAs
26
29
  identifies_as_hash[ this_object ] = true
27
30
  end
28
31
 
32
+ if do_not_identify_as_hash = @do_not_identify_as[ object_id ]
33
+ objects.each do |this_object|
34
+ do_not_identify_as_hash.delete( this_object )
35
+ end
36
+ end
37
+
29
38
  return identifies_as_hash
30
39
 
31
40
  end
@@ -45,6 +54,12 @@ module ::IdentifiesAs
45
54
  identifies_as_hash[ this_object ] = true
46
55
  end
47
56
 
57
+ if do_not_identify_as_hash = @instances_do_not_identify_as[ object_class ]
58
+ objects.each do |this_object|
59
+ do_not_identify_as_hash.delete( object_class )
60
+ end
61
+ end
62
+
48
63
  return identifies_as_hash
49
64
 
50
65
  end
@@ -57,10 +72,15 @@ module ::IdentifiesAs
57
72
 
58
73
  object_identifies = object_instance_identifies_as?( object, other_object_type )
59
74
 
60
- unless object_identifies
75
+ # If we got nil that means we were told to stop looking.
76
+ unless object_identifies or object_identifies.nil?
61
77
  object_identifies = object_instances_identify_as?( object.class, other_object_type )
62
78
  end
63
79
 
80
+ if object_identifies.nil?
81
+ object_identifies = false
82
+ end
83
+
64
84
  return object_identifies
65
85
 
66
86
  end
@@ -87,8 +107,14 @@ module ::IdentifiesAs
87
107
  end
88
108
 
89
109
  object_ancestor_chain.each do |this_ancestor|
90
-
91
- if identifies_as_hash = @identities[ this_ancestor.__id__ ]
110
+
111
+ this_ancestor_id = this_ancestor.__id__
112
+
113
+ if do_not_identify_as_hash = @do_not_identify_as[ this_ancestor_id ] and
114
+ do_not_identify_as_hash.has_key?( other_object_type )
115
+ object_identifies = nil
116
+ break
117
+ elsif identifies_as_hash = @identities[ this_ancestor_id ]
92
118
  break if object_identifies = identifies_as_hash.has_key?( other_object_type )
93
119
  end
94
120
 
@@ -105,11 +131,15 @@ module ::IdentifiesAs
105
131
  def self.object_instances_identify_as?( object_class, other_object_type )
106
132
 
107
133
  object_identifies = false
108
-
109
134
  object_class.ancestors.each do |this_ancestor|
110
- if identifies_as_hash = @instance_identities[ this_ancestor ]
135
+ if do_not_identify_as_hash = @instances_do_not_identify_as[ this_ancestor ] and
136
+ do_not_identify_as_hash.has_key?( other_object_type )
137
+ object_identifies = nil
138
+ break
139
+ elsif identifies_as_hash = @instance_identities[ this_ancestor ]
111
140
  object_identifies = identifies_as_hash.has_key?( other_object_type )
112
141
  end
142
+
113
143
  end
114
144
 
115
145
  return object_identifies
@@ -157,26 +187,37 @@ module ::IdentifiesAs
157
187
  end
158
188
 
159
189
  ######################################
160
- # self.object_stop_identifying_as! #
190
+ # self.stop_object_identifying_as! #
161
191
  ######################################
162
192
 
163
- def self.object_stop_identifying_as!( object, *objects )
193
+ def self.stop_object_identifying_as!( object, *objects )
194
+
195
+ object_id = object.__id__
164
196
 
165
- if identifies_as_hash = @identities[ object.__id__ ]
197
+ if identifies_as_hash = @identities[ object_id ]
166
198
  objects.each do |this_object|
167
199
  identifies_as_hash.delete( this_object )
168
200
  end
169
201
  end
202
+
203
+ unless do_not_identify_as_hash = @do_not_identify_as[ object_id ]
204
+ do_not_identify_as_hash = { }
205
+ @do_not_identify_as[ object_id ] = do_not_identify_as_hash
206
+ end
207
+
208
+ objects.each do |this_object|
209
+ do_not_identify_as_hash[ this_object ] = true
210
+ end
170
211
 
171
212
  return identifies_as_hash
172
213
 
173
214
  end
174
215
 
175
216
  ################################################
176
- # self.object_stop_instances_identifying_as! #
217
+ # self.stop_object_instances_identifying_as! #
177
218
  ################################################
178
219
 
179
- def self.object_stop_instances_identifying_as!( object_class, *objects )
220
+ def self.stop_object_instances_identifying_as!( object_class, *objects )
180
221
 
181
222
  if identifies_as_hash = @instance_identities[ object_class ]
182
223
  object_identifies = identifies_as_hash.has_key?( object_class )
@@ -184,7 +225,16 @@ module ::IdentifiesAs
184
225
  object_identifies.delete( this_object )
185
226
  end
186
227
  end
187
-
228
+
229
+ unless do_not_identify_as_hash = @instances_do_not_identify_as[ object_class ]
230
+ do_not_identify_as_hash = { }
231
+ @instances_do_not_identify_as[ object_class ] = do_not_identify_as_hash
232
+ end
233
+
234
+ objects.each do |this_object|
235
+ do_not_identify_as_hash[ this_object ] = true
236
+ end
237
+
188
238
  return identifies_as_hash
189
239
 
190
240
  end
@@ -87,15 +87,15 @@ describe ::IdentifiesAs do
87
87
  ( AlsoNotAnArray <=> AlsoNotAnArray ).should == 0
88
88
  ( AlsoNotAnArray <=> Unrelated ).should == nil
89
89
 
90
- instance = NotAnArray.new
91
- instance.identifies_as?( Array ).should == true
92
- instance.is_a?( Array ).should == true
93
- ( Array === instance ).should == true
90
+ not_an_array_instance = NotAnArray.new
91
+ not_an_array_instance.identifies_as?( Array ).should == true
92
+ not_an_array_instance.is_a?( Array ).should == true
93
+ ( Array === not_an_array_instance ).should == true
94
94
 
95
- instance = AlsoNotAnArray.new
96
- instance.identifies_as?( Array ).should == true
97
- instance.is_a?( Array ).should == true
98
- ( Array === instance ).should == true
95
+ also_not_an_array_instance = AlsoNotAnArray.new
96
+ also_not_an_array_instance.identifies_as?( Array ).should == true
97
+ also_not_an_array_instance.is_a?( Array ).should == true
98
+ ( Array === also_not_an_array_instance ).should == true
99
99
 
100
100
  module IncludersActLikeArray
101
101
  include IdentifiesAs
@@ -106,6 +106,12 @@ describe ::IdentifiesAs do
106
106
  include IncludersActLikeArray
107
107
  end
108
108
 
109
+ another_non_array_instance = AnotherNonArray.new
110
+ another_non_array_instance.identifies_as?( Array ).should == true
111
+ another_non_array_instance.is_a?( Array ).should == true
112
+ ( Array === another_non_array_instance ).should == true
113
+
114
+
109
115
  module IncludersAlsoActLikeArray
110
116
  include IncludersActLikeArray
111
117
  end
@@ -114,10 +120,20 @@ describe ::IdentifiesAs do
114
120
  include IncludersAlsoActLikeArray
115
121
  end
116
122
 
117
- instance = AnotherNonArray.new
118
- instance.identifies_as?( Array ).should == true
119
- instance.is_a?( Array ).should == true
120
- ( Array === instance ).should == true
123
+ and_another_non_array_instance = AndAnotherNonArray.new
124
+ and_another_non_array_instance.identifies_as?( Array ).should == true
125
+ and_another_non_array_instance.is_a?( Array ).should == true
126
+ ( Array === and_another_non_array_instance ).should == true
127
+
128
+ AndAnotherNonArray.stop_instances_identifying_as!( Array )
129
+ and_another_non_array_instance.identifies_as?( Array ).should == false
130
+ and_another_non_array_instance.is_a?( Array ).should == false
131
+ ( Array === and_another_non_array_instance ).should == false
132
+
133
+ AnotherNonArray.stop_instances_identifying_as!( Array )
134
+ another_non_array_instance.identifies_as?( Array ).should == false
135
+ another_non_array_instance.is_a?( Array ).should == false
136
+ ( Array === another_non_array_instance ).should == false
121
137
 
122
138
  end
123
139
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: identifies_as
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: