Class: DioTests::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/dio_tests/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
# File 'lib/dio_tests/client.rb', line 7

def initialize(args={})
  @format = args[:format]
  @since_commit = args[:since_commit] || "master"
  @author = args[:author] || git_config("user.name")
end

Instance Attribute Details

#minus_countObject (readonly)

Returns the value of attribute minus_count.



5
6
7
# File 'lib/dio_tests/client.rb', line 5

def minus_count
  @minus_count
end

#plus_countObject (readonly)

Returns the value of attribute plus_count.



5
6
7
# File 'lib/dio_tests/client.rb', line 5

def plus_count
  @plus_count
end

Class Method Details

.format_pattern(format) ⇒ Object



44
45
46
47
48
49
# File 'lib/dio_tests/client.rb', line 44

def self.format_pattern(format)
  raise "format is require" unless format

  raise "Not found: #{format} in formats.yml" unless formats[format]
  formats[format]
end

.formatsObject



51
52
53
# File 'lib/dio_tests/client.rb', line 51

def self.formats
  formats = YAML.load_file("#{File.dirname(__FILE__)}/formats.yml")
end

Instance Method Details

#git_config(name) ⇒ Object



40
41
42
# File 'lib/dio_tests/client.rb', line 40

def git_config(name)
  `git config --get #{name}`.strip
end

#git_logObject



34
35
36
37
38
# File 'lib/dio_tests/client.rb', line 34

def git_log
  git_log_command = "git log --author=#{@author} --remove-empty --oneline --unified=0 --ignore-all-space #{@since_commit}..HEAD"
  puts git_log_command
  `#{git_log_command}`
end


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dio_tests/client.rb', line 13

def print_test_count
  format_pattern = DioTests::Client.format_pattern(@format)
  log = git_log

  @plus_count = log.each_line.select{|line| line[0] == "+"}.
    inject(0){|count, line|
      line[0] = ""
      count += 1 if line =~ /#{format_pattern}/
      count
    } || 0

  @minus_count = log.each_line.select{|line| line[0] == "-"}.
    inject(0){|count, line|
      line[0] = ""
      count += 1 if line =~ /#{format_pattern}/
      count
    } || 0

  puts "plus=#{@plus_count}, minus=#{@minus_count}, increment=#{@plus_count - @minus_count}"
end