Class: CycleDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/kwala/lib/cycle_detector.rb

Defined Under Namespace

Classes: DKWonMLPrintStrategy, DOTPrintStrategy, GraphMLPrintStrategy, Node, STDOUTPrintStrategy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCycleDetector

Returns a new instance of CycleDetector.



52
53
54
55
56
57
58
59
60
61
# File 'lib/kwala/lib/cycle_detector.rb', line 52

def initialize
  @graph = Hash.new
  @print_strategy = STDOUTPrintStrategy.new
  @filter = Proc.new do |files|
    files.find_all do |f|
      /tests\// !~ f && /extensions\// !~ f &&
        /tools\// !~ f && /\/ms\// !~ f && /\/site\// !~f
    end
  end
end

Instance Attribute Details

Sets the attribute print_strategy

Parameters:

  • value

    the value to set the attribute print_strategy to.



50
51
52
# File 'lib/kwala/lib/cycle_detector.rb', line 50

def print_strategy=(value)
  @print_strategy = value
end

Instance Method Details

#find_cyclesObject



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/kwala/lib/cycle_detector.rb', line 76

def find_cycles
  cycles = Array.new
  @graph.each do |req, node|

    cycle = find_cycle(node, [])
    if cycle
      cycles<< cycle
    end

    reset_state
  end
  cycles
end

#make_graph(dir, convert = nil) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/kwala/lib/cycle_detector.rb', line 63

def make_graph(dir, convert = nil)
  files = ReqWalker.find_ruby_files(dir)

  if convert
    files = ReqWalker.convert_files_path_to(files, convert.from, convert.to)
  end

  files = @filter.call(files)

  build_graph_from_edges(files)
  reset_state
end


101
102
103
104
105
# File 'lib/kwala/lib/cycle_detector.rb', line 101

def print_cycles(cycles)
  reset_state
  @print_strategy.print_cycles(cycles)
  reset_state
end


95
96
97
98
99
# File 'lib/kwala/lib/cycle_detector.rb', line 95

def print_graph
  reset_state
  @print_strategy.print_graph(@graph)
  reset_state
end


107
108
109
110
111
# File 'lib/kwala/lib/cycle_detector.rb', line 107

def print_unique_cycles(cycles)
  reset_state
  @print_strategy.print_cycles( unique_cycles(cycles) )
  reset_state
end

#sizeObject



90
91
92
# File 'lib/kwala/lib/cycle_detector.rb', line 90

def size
  @graph.size
end