Class: Turbulence::CommandLineInterface

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/turbulence/cli_parser.rb,
lib/turbulence/command_line_interface.rb

Defined Under Namespace

Modules: ConfigParser

Constant Summary collapse

TURBULENCE_TEMPLATE_PATH =
File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "template")
TEMPLATE_FILES =
[
  'turbulence.html',
  'highcharts.js',
  'highcharts-heatmap.js',
  'highcharts-treemap.js',
  'jquery.min.js',
  'treemap.html',
].map do |filename|
  File.join(TURBULENCE_TEMPLATE_PATH, filename)
end

Instance Method Summary collapse

Constructor Details

#initialize(argv, additional_options = {}) ⇒ CommandLineInterface

Returns a new instance of CommandLineInterface.



26
27
28
29
# File 'lib/turbulence/command_line_interface.rb', line 26

def initialize(argv, additional_options = {})
  ConfigParser.parse_argv_into_config argv, config
  config.output = additional_options.fetch(:output, STDOUT)
end

Instance Method Details

#copy_templates_into(directory) ⇒ Object



46
47
48
# File 'lib/turbulence/command_line_interface.rb', line 46

def copy_templates_into(directory)
  FileUtils.cp TEMPLATE_FILES, directory
end

#generate_bundleObject



50
51
52
53
54
55
56
# File 'lib/turbulence/command_line_interface.rb', line 50

def generate_bundle
  if json_output
    generate_json
  else
    generate_html
  end
end

#generate_htmlObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/turbulence/command_line_interface.rb', line 65

def generate_html
  FileUtils.mkdir_p(output_path)

  Dir.chdir(output_path) do
    turb = Turbulence.new(config)

    generator = case graph_type
    when "treemap"
      Turbulence::Generators::TreeMap.new({})
    else
      Turbulence::Generators::ScatterPlot.new({})
    end

    generator.generate_results(turb.metrics, self)
  end
end

#generate_jsonObject



58
59
60
61
62
63
# File 'lib/turbulence/command_line_interface.rb', line 58

def generate_json
  # Suppress progress output for clean JSON
  config.output = nil
  turb = Turbulence.new(config)
  puts JSON.pretty_generate(turb.metrics)
end

#open_bundleObject



82
83
84
# File 'lib/turbulence/command_line_interface.rb', line 82

def open_bundle
  Launchy.open("file:///#{output_path}/#{graph_type}.html")
end

#output_pathObject



42
43
44
# File 'lib/turbulence/command_line_interface.rb', line 42

def output_path
  output_dir || File.join(Dir.pwd, "turbulence")
end