Class: RubyDetective::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_detective/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_path) ⇒ Runner

Returns a new instance of Runner.



7
8
9
10
11
12
13
# File 'lib/ruby_detective/runner.rb', line 7

def initialize(project_path)
  if [nil, "", " "].include? project_path
    @project_path = "."
  else
    @project_path = project_path
  end
end

Instance Attribute Details

#classesObject (readonly)

Returns the value of attribute classes.



5
6
7
# File 'lib/ruby_detective/runner.rb', line 5

def classes
  @classes
end

#modulesObject (readonly)

Returns the value of attribute modules.



5
6
7
# File 'lib/ruby_detective/runner.rb', line 5

def modules
  @modules
end

#project_pathObject (readonly)

Returns the value of attribute project_path.



5
6
7
# File 'lib/ruby_detective/runner.rb', line 5

def project_path
  @project_path
end

Instance Method Details

#runObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ruby_detective/runner.rb', line 15

def run
  puts "Processing files..."
  Dir.glob("#{project_path}/**/*.rb") do |file_path|
    AST::FileParser.new(file_path, project_path).parse
  end

  puts "Finding dependencies..."
  SourceRepresentation::DataStore.instance.resolve_dependencies

  if ENV["ENV"] == "development"
    puts "Generating output .json file..."
    json = ::RubyDetective::JSONBuilder.build

    output_file_path = "ui/src/data.json"
    File.delete(output_file_path) if File.exist?(output_file_path)
    File.open(output_file_path, "w") { |file| file << json }
  else
    puts "Generating output HTML file..."
    UIGenerator.generate
  end

  puts "Done!"
end