Module: IdentifiesAs

Defined in:
lib/requires.rb,
lib/identifies_as.rb,
lib/identifies_as.rb

Defined Under Namespace

Modules: ActuallyIsA, ObjectInstance

Class Method Summary collapse

Class Method Details

.included(module_instance) ⇒ Object

self.included #



20
21
22
23
24
25
26
# File 'lib/identifies_as.rb', line 20

def self.included( module_instance )
  
  super if defined?( super )
  
  module_instance.extend( self )
  
end

.object_identifies_as!(object, *objects) ⇒ Object

self.object_identifies_as! #



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/identifies_as.rb', line 32

def self.object_identifies_as!( object, *objects )

  object_id = object.__id__
        
  unless identifies_as_hash = @identities[ object_id ]
    identifies_as_hash = { }
    @identities[ object_id ] = identifies_as_hash
  end
  
  objects.each do |this_object|
    identifies_as_hash[ this_object ] = true
  end
  
  if do_not_identify_as_hash = @do_not_identify_as[ object_id ]
    objects.each do |this_object|
      do_not_identify_as_hash.delete( this_object )
    end
  end
  
  return identifies_as_hash
  
end

.object_identifies_as?(object, other_object_type) ⇒ Boolean

self.object_identifies_as? #

Returns:

  • (Boolean)


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/identifies_as.rb', line 84

def self.object_identifies_as?( object, other_object_type )
  
  object_identifies = object_instance_identifies_as?( object, other_object_type )

  # If we got nil that means we were told to stop looking.
  unless object_identifies or object_identifies.nil?
    object_identifies = object_instances_identify_as?( object.class, other_object_type )
  end
  
  if object_identifies.nil?
    object_identifies = false
  end
  
  return object_identifies
  
end

.object_identities(object) ⇒ Object

self.object_identities #



166
167
168
169
170
# File 'lib/identifies_as.rb', line 166

def self.object_identities( object )
  
  return object_identities_hash( object ).keys
  
end

.object_identities_hash(object) ⇒ Object

self.object_identities_hash #



186
187
188
189
190
# File 'lib/identifies_as.rb', line 186

def self.object_identities_hash( object )
  
  return @identities[ object.__id__ ]
  
end

.object_instance_identifies_as?(object, other_object_type) ⇒ Boolean

self.object_instance_identifies_as? #

Returns:

  • (Boolean)


105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/identifies_as.rb', line 105

def self.object_instance_identifies_as?( object, other_object_type )
  
  object_identifies = false
  
  object_ancestor_chain = nil

  if ::Module.case_compare( object )
    object_ancestor_chain = object.ancestors.dup
  else
    object_ancestor_chain = [ object ]
    if ::Symbol.case_compare( object ) or ::Fixnum.case_compare( object )
      object_ancestor_chain.concat( object.class.ancestors )
    else
      object_ancestor_chain.concat( class << object ; ancestors ; end )
    end
  end

  object_ancestor_chain.each do |this_ancestor|

    this_ancestor_id = this_ancestor.__id__

    if do_not_identify_as_hash = @do_not_identify_as[ this_ancestor_id ] and
       do_not_identify_as_hash.has_key?( other_object_type )
      object_identifies = nil
      break
    elsif identifies_as_hash = @identities[ this_ancestor_id ]
      break if object_identifies = identifies_as_hash.has_key?( other_object_type )
    end

  end
  
  return object_identifies
  
end

.object_instance_identities(object_class) ⇒ Object

self.object_instance_identities #



176
177
178
179
180
# File 'lib/identifies_as.rb', line 176

def self.object_instance_identities( object_class )
  
  return object_instance_identities_hash( object_class ).keys
  
end

.object_instance_identities_hash(object_class) ⇒ Object

self.object_instance_identities_hash #



196
197
198
199
200
# File 'lib/identifies_as.rb', line 196

def self.object_instance_identities_hash( object_class )
  
  return @instance_identities[ object_class ]
  
end

.object_instances_identify_as!(object_class, *objects) ⇒ Object

self.object_instances_identify_as! #



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/identifies_as.rb', line 59

def self.object_instances_identify_as!( object_class, *objects )

  unless identifies_as_hash = @instance_identities[ object_class ]
    identifies_as_hash = { }
    @instance_identities[ object_class ] = identifies_as_hash
  end
  
  objects.each do |this_object|
    identifies_as_hash[ this_object ] = true
  end
  
  if do_not_identify_as_hash = @instances_do_not_identify_as[ object_class ]
    objects.each do |this_object|
      do_not_identify_as_hash.delete( object_class )
    end
  end
  
  return identifies_as_hash
  
end

.object_instances_identify_as?(object_class, other_object_type) ⇒ Boolean

self.object_instances_identify_as? #

Returns:

  • (Boolean)


144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/identifies_as.rb', line 144

def self.object_instances_identify_as?( object_class, other_object_type )

  object_identifies = false
  object_class.ancestors.each do |this_ancestor|
    if do_not_identify_as_hash = @instances_do_not_identify_as[ this_ancestor ] and
       do_not_identify_as_hash.has_key?( other_object_type )
        object_identifies = nil
        break
    elsif identifies_as_hash = @instance_identities[ this_ancestor ]
      break if object_identifies = identifies_as_hash.has_key?( other_object_type )
    end

  end

  return object_identifies
  
end

.stop_object_identifying_as!(object, *objects) ⇒ Object

self.stop_object_identifying_as! #



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/identifies_as.rb', line 206

def self.stop_object_identifying_as!( object, *objects )

  object_id = object.__id__

  if identifies_as_hash = @identities[ object_id ]
    objects.each do |this_object|
      identifies_as_hash.delete( this_object )
    end
  end

  unless do_not_identify_as_hash = @do_not_identify_as[ object_id ]
    do_not_identify_as_hash = { }
    @do_not_identify_as[ object_id ] = do_not_identify_as_hash
  end

  objects.each do |this_object|
    do_not_identify_as_hash[ this_object ] = true
  end
  
  return identifies_as_hash

end

.stop_object_instances_identifying_as!(object_class, *objects) ⇒ Object

self.stop_object_instances_identifying_as! #



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/identifies_as.rb', line 233

def self.stop_object_instances_identifying_as!( object_class, *objects )

  if identifies_as_hash = @instance_identities[ object_class ]
    object_identifies = identifies_as_hash.has_key?( object_class )
    objects.each do |this_object|
      object_identifies.delete( this_object )
    end
  end

  unless do_not_identify_as_hash = @instances_do_not_identify_as[ object_class ]
    do_not_identify_as_hash = { }
    @instances_do_not_identify_as[ object_class ] = do_not_identify_as_hash
  end

  objects.each do |this_object|
    do_not_identify_as_hash[ this_object ] = true
  end

  return identifies_as_hash

end