Class: Robe::TypeSpace

Inherits:
Object
  • Object
show all
Defined in:
lib/robe/type_space.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(visor, target, mod, instance, superc) ⇒ TypeSpace

Returns a new instance of TypeSpace.



7
8
9
10
11
12
# File 'lib/robe/type_space.rb', line 7

def initialize(visor, target, mod, instance, superc)
  @visor = visor
  @instance = instance
  @superc = superc
  guess_target_type(target, mod)
end

Instance Attribute Details

#instanceObject (readonly)

Returns the value of attribute instance.



5
6
7
# File 'lib/robe/type_space.rb', line 5

def instance
  @instance
end

#target_typeObject (readonly)

Returns the value of attribute target_type.



5
6
7
# File 'lib/robe/type_space.rb', line 5

def target_type
  @target_type
end

#visorObject (readonly)

Returns the value of attribute visor.



5
6
7
# File 'lib/robe/type_space.rb', line 5

def visor
  @visor
end

Instance Method Details

#scan_with(scanner) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/robe/type_space.rb', line 14

def scan_with(scanner)
  return unless obj = target_type
  modules = obj.ancestors
  modules -= obj.included_modules unless instance

  if @superc
    modules -= [obj]
  else
    modules += visor.descendants(obj).to_a
  end

  modules.push(Kernel) if instance && !obj.is_a?(Class)

  if instance
    if defined? ActiveSupport::Concern and obj.is_a?(ActiveSupport::Concern)
      deps = obj.instance_variable_get("@_dependencies")
      modules += deps if deps
    end
  end

  scanner.scan(modules, instance, !instance)

  unless instance
    singleton_ancestors = obj.singleton_class.ancestors

    if RUBY_VERSION >= "2.1.0"
      # Ruby 2.1 includes all singletons in the ancestors chain
      singleton_ancestors.reject!(&:__singleton_class__?)
    end

    scanner.scan(singleton_ancestors, true, false)
  end
end