Class: CodeNode::SpecHelpers::DotFile

Inherits:
Object
  • Object
show all
Includes:
Cog::SpecHelpers
Defined in:
lib/code_node/spec_helpers/dot_file.rb

Overview

Represents a generated dot file

Instance Method Summary collapse

Methods included from Cog::SpecHelpers

#spec_root

Constructor Details

#initialize(name) ⇒ DotFile

Returns a new instance of DotFile.

Parameters:

  • name (String)

    name of the dotfile without the .dot extension. The file will be looked for in the lib subdirectory of the active fixture dir.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/code_node/spec_helpers/dot_file.rb', line 10

def initialize(name)
  @filename = generated_file "#{name}.dot"
  @nodes = {} # :node_type => []
  @edges = {} # :edge_type => []
  if File.exists? @filename
    @i = 0
    @lines = File.read(@filename).split "\n"
    read_until '/* Module nodes */'
    read_nodes :module
    read_until '/* Class nodes */'
    read_nodes :class
    read_until '/* A contains B */'
    read_edges :containment
    read_until '/* A inherits from B */'
    read_edges :inheritance
    read_until '/* A includes B */'
    read_edges :inclusion
    read_until '/* A extends B */'
    read_edges :extension
  end
end

Instance Method Details

#exists?Boolean

Returns does the file exist?.

Returns:

  • (Boolean)

    does the file exist?



33
34
35
# File 'lib/code_node/spec_helpers/dot_file.rb', line 33

def exists?
  File.exists? @filename
end

#has_class?(path) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
# File 'lib/code_node/spec_helpers/dot_file.rb', line 47

def has_class?(path)
  key = path.to_s.split('::').join '_'
  @nodes[:class].member?(key)
end

#has_containment?(path1, path2) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/code_node/spec_helpers/dot_file.rb', line 61

def has_containment?(path1, path2)
  has_relation? :containment, path1, path2
end

#has_edge?(path1, path2) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/code_node/spec_helpers/dot_file.rb', line 57

def has_edge?(path1, path2)
  has_containment?(path1, path2) || has_inheritance?(path1, path2) || has_inclusion?(path1, path2) || has_extension?(path1, path2)
end

#has_extension?(path1, path2) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/code_node/spec_helpers/dot_file.rb', line 73

def has_extension?(path1, path2)
  has_relation? :extension, path1, path2
end

#has_inclusion?(path1, path2) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/code_node/spec_helpers/dot_file.rb', line 69

def has_inclusion?(path1, path2)
  has_relation? :inclusion, path1, path2
end

#has_inheritance?(path1, path2) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/code_node/spec_helpers/dot_file.rb', line 65

def has_inheritance?(path1, path2)
  has_relation? :inheritance, path1, path2
end

#has_match?(pattern) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
# File 'lib/code_node/spec_helpers/dot_file.rb', line 37

def has_match?(pattern)
  if exists?
    !!(pattern =~ File.read(@filename))
  end
end

#has_module?(path) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
# File 'lib/code_node/spec_helpers/dot_file.rb', line 52

def has_module?(path)
  key = path.to_s.split('::').join '_'
  @nodes[:module].member?(key)
end

#has_node?(path) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/code_node/spec_helpers/dot_file.rb', line 43

def has_node?(path)
  has_class?(path) || has_module?(path)
end