identifies_as 1.0.10 → 1.1.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.
@@ -62,7 +62,8 @@ module ::IdentifiesAs::ObjectInstance
62
62
 
63
63
  is_type = false
64
64
 
65
- if identifies_as?( object )
65
+ if actually_is_a?( ::IdentifiesAs ) and
66
+ identifies_as?( object )
66
67
  is_type = true
67
68
  else
68
69
  is_type = super
data/lib/identifies_as.rb CHANGED
@@ -13,6 +13,18 @@ module ::IdentifiesAs
13
13
  @do_not_identify_as = { }
14
14
  @instances_do_not_identify_as = { }
15
15
 
16
+ ###################
17
+ # self.included #
18
+ ###################
19
+
20
+ def self.included( module_instance )
21
+
22
+ super if defined?( super )
23
+
24
+ module_instance.extend( self )
25
+
26
+ end
27
+
16
28
  ################################
17
29
  # self.object_identifies_as! #
18
30
  ################################
@@ -70,7 +82,7 @@ module ::IdentifiesAs
70
82
  ################################
71
83
 
72
84
  def self.object_identifies_as?( object, other_object_type )
73
-
85
+
74
86
  object_identifies = object_instance_identifies_as?( object, other_object_type )
75
87
 
76
88
  # If we got nil that means we were told to stop looking.
@@ -95,7 +107,7 @@ module ::IdentifiesAs
95
107
  object_identifies = false
96
108
 
97
109
  object_ancestor_chain = nil
98
-
110
+
99
111
  if object.actually_is_a?( ::Module )
100
112
  object_ancestor_chain = object.ancestors.dup
101
113
  else
@@ -138,11 +150,11 @@ module ::IdentifiesAs
138
150
  object_identifies = nil
139
151
  break
140
152
  elsif identifies_as_hash = @instance_identities[ this_ancestor ]
141
- object_identifies = identifies_as_hash.has_key?( other_object_type )
153
+ break if object_identifies = identifies_as_hash.has_key?( other_object_type )
142
154
  end
143
155
 
144
156
  end
145
-
157
+
146
158
  return object_identifies
147
159
 
148
160
  end
@@ -241,7 +253,3 @@ module ::IdentifiesAs
241
253
  end
242
254
 
243
255
  end
244
-
245
- class ::Object
246
- include ::IdentifiesAs
247
- end
data/lib/module.rb CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  class ::Module
3
-
3
+
4
4
  ############################
5
5
  # instances_identify_as! #
6
6
  ############################
@@ -63,7 +63,9 @@ class ::Module
63
63
 
64
64
  is_equal = false
65
65
 
66
- if ::IdentifiesAs.respond_to?( :object_identifies_as? ) and ::IdentifiesAs.object_identifies_as?( object, self )
66
+ if ::IdentifiesAs.respond_to?( :object_identifies_as? ) and
67
+ object.actually_is_a?( ::IdentifiesAs ) and
68
+ ::IdentifiesAs.object_identifies_as?( object, self )
67
69
  is_equal = true
68
70
  else
69
71
  is_equal = case_compare( object )
@@ -85,7 +87,8 @@ class ::Module
85
87
 
86
88
  if is_less_than.nil?
87
89
  # a class is < another class if it has the other class as one of its ancestors
88
- if self != object and ::IdentifiesAs.object_instance_identifies_as?( self, object )
90
+ if self != object and
91
+ ::IdentifiesAs.object_instance_identifies_as?( self, object )
89
92
  is_less_than = true
90
93
  end
91
94
  end
@@ -106,7 +109,8 @@ class ::Module
106
109
 
107
110
  if is_greater_than.nil?
108
111
  # a class is > another class if the other class has it as one of its ancestors
109
- if self != object and ::IdentifiesAs.object_instance_identifies_as?( object, self )
112
+ if self != object and
113
+ ::IdentifiesAs.object_instance_identifies_as?( object, self )
110
114
  is_greater_than = true
111
115
  else
112
116
  is_less_than = self < object
@@ -132,7 +136,8 @@ class ::Module
132
136
 
133
137
  if is_less_than_or_equal_to.nil?
134
138
  # a class is < another class if it has the other class as one of its ancestors
135
- if self == object or ::IdentifiesAs.object_instance_identifies_as?( self, object )
139
+ if self == object or
140
+ ::IdentifiesAs.object_instance_identifies_as?( self, object )
136
141
  is_less_than_or_equal_to = true
137
142
  end
138
143
  end
@@ -153,7 +158,8 @@ class ::Module
153
158
 
154
159
  if is_greater_than_or_equal_to.nil?
155
160
  # a class is < another class if it has the other class as one of its ancestors
156
- if self == object or ::IdentifiesAs.object_instance_identifies_as?( object, self )
161
+ if self == object or
162
+ ::IdentifiesAs.object_instance_identifies_as?( object, self )
157
163
  is_greater_than_or_equal_to = true
158
164
  else
159
165
  is_less_than_or_equal_to = self <= object
data/lib/requires.rb CHANGED
@@ -19,5 +19,6 @@ files.each do |this_file|
19
19
  end
20
20
 
21
21
  class ::Object
22
+ include ::IdentifiesAs::ActuallyIsA
22
23
  include ::IdentifiesAs::ObjectInstance
23
24
  end
@@ -18,6 +18,7 @@ describe ::IdentifiesAs do
18
18
  it 'lets an object pretend it is another object' do
19
19
 
20
20
  instance = Object.new
21
+ instance.extend( ::IdentifiesAs )
21
22
 
22
23
  instance.identifies_as!( Array )
23
24
  instance.identifies_as?( Array ).should == true
@@ -54,6 +55,7 @@ describe ::IdentifiesAs do
54
55
  end
55
56
 
56
57
  class NotAnArray
58
+ include ::IdentifiesAs
57
59
  identifies_as!( Array )
58
60
  instances_identify_as!( Array )
59
61
  identifies_as!( SomeOtherClass )
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.10
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-05 00:00:00.000000000 Z
12
+ date: 2012-07-22 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Identities are interfaces. Sometimes it makes more sense to test an identity
15
15
  than a method- but then you don't want to limit flexibility. So why not let objects
@@ -24,7 +24,6 @@ files:
24
24
  - lib/identifies_as/object_instance.rb
25
25
  - lib/identifies_as.rb
26
26
  - lib/module.rb
27
- - lib/namespaces.rb
28
27
  - lib/requires.rb
29
28
  - spec/identifies_as_spec.rb
30
29
  - README.md
@@ -40,7 +39,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
40
39
  requirements:
41
40
  - - ! '>='
42
41
  - !ruby/object:Gem::Version
43
- version: '0'
42
+ version: 1.9.1
44
43
  required_rubygems_version: !ruby/object:Gem::Requirement
45
44
  none: false
46
45
  requirements:
data/lib/namespaces.rb DELETED
File without changes