Class: Jetmeter::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/jetmeter/cli.rb

Constant Summary collapse

CREDENTIAL_PATH =
File.expand_path('~/.jetmeter/token').freeze
CACHE_PATH =
File.expand_path('~/.jetmeter/cache').freeze

Instance Method Summary collapse

Constructor Details

#initialize(config_path) ⇒ CLI

Returns a new instance of CLI.



6
7
8
9
10
# File 'lib/jetmeter/cli.rb', line 6

def initialize(config_path)
  @config = eval(File.read(config_path))
  prepare_cache
  authenticate_user
end

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/jetmeter/cli.rb', line 12

def run
  puts "Receiving issue events..."
  repository_issue_events = Jetmeter::Collection.new(
    Jetmeter::RepositoryIssueEventsLoader.new(@config).load,
    Jetmeter::IssueEventAdapter
  )

  puts "Receiving issues..."
  repository_issues = Jetmeter::Collection.new(
    Jetmeter::RepositoryIssuesLoader.new(@config).load,
    Jetmeter::IssueAdapter
  )

  accums = [
    Jetmeter::OpenAccumulator.new,
    Jetmeter::LabelAccumulator.new,
    Jetmeter::LabelAccumulator.new(additive: false),
    Jetmeter::CloseAccumulator.new,
    Jetmeter::CloseAccumulator.new(additive: false),
    Jetmeter::MergeAccumulator.new
  ]
  filters = [
    Jetmeter::DateFilter.new,
    Jetmeter::OpenFilter.new(repository_issues)
  ]

  reducer = Jetmeter::FlowReducer.new(
    [repository_issues, repository_issue_events],
    @config
  )

  puts "Analyzing received data..."
  reducer.reduce(accums, filters)

  puts "Initializing CSV formatter..."
  formatter = Jetmeter::CsvFormatter.new(@config, reducer)

  puts "Saving CSV file..."
  File.open(@config.output_path, 'wb') do |file|
    formatter.save(file)
    puts "Created CSV: #{@config.output_path}"
  end
end