Module: DependencyGrapher::ParseClass

Defined in:
lib/dependency_grapher/parse_class.rb

Class Method Summary collapse

Class Method Details

.anon_class_pattern?(name) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/dependency_grapher/parse_class.rb', line 23

def anon_class_pattern?(name)
  name.match(nested_anon_pattern) || name.match(anon_pattern)
end

.anon_patternObject

#<Class:0x007fd550c04338> matches with groups: 1.Class 2.0x007fd550c04338



19
20
21
# File 'lib/dependency_grapher/parse_class.rb', line 19

def anon_pattern 
  /#<(Class|Module):([^>]*)>/
end

.call(klass) ⇒ Object



4
5
6
# File 'lib/dependency_grapher/parse_class.rb', line 4

def call(klass)
  anon_class_pattern?(klass.inspect) ? parse_anon_class_name(klass.inspect) : klass.inspect
end

.nested_anon_patternObject

#<#<Class:0x007fd550c04338>:0x007fd550c04450> matches with groups: 1.#<Class:0x007fd550c04338> 2.0x007fd550c04450



12
13
14
# File 'lib/dependency_grapher/parse_class.rb', line 12

def nested_anon_pattern 
  /#<(#<.*>):(.*)>/
end

.parse_anon_class_name(name) ⇒ Object

Given #<#<Class:0x007fd550c04338>:0x007fd550c04450>, returns string “0x007fd550c04338::0x007fd550c04450” using a recursive function



29
30
31
32
33
34
35
36
37
# File 'lib/dependency_grapher/parse_class.rb', line 29

def parse_anon_class_name(name)
  if match = name.match(nested_anon_pattern)
    parse_anon_class_name(match[1]) + "::#{match[2]}"
  elsif match = name.match(anon_pattern)
    match[2]
  else
    raise "Unrecognized format for Class or Module: #{name}."
  end
end