Class: ShowCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/teuton/check/show.rb

Instance Method Summary collapse

Constructor Details

#initialize(stats:, path:) ⇒ ShowCheck



9
10
11
12
# File 'lib/teuton/check/show.rb', line 9

def initialize(stats:, path:)
  @stats = stats
  @path = path
end

Instance Method Details

#revise_config_contentObject



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
# File 'lib/teuton/check/show.rb', line 21

def revise_config_content
  unless File.exist?(@path[:config])
    Logger.warn "[WARN] Configfile not found"
    Logger.debug "       #{@path[:config]}"
    Logger.warn "[INFO] Recomended content:"
    suggest_config_content
    return
  end

  script_vars = find_script_vars
  config_vars = ConfigFileReader.read(@path[:config])
  config_vars[:global]&.each_key { |k| script_vars.delete(k) }
  config_vars[:alias]&.each_key { |k| script_vars.delete(k) }

  config_vars[:cases].each_with_index do |item, index|
    next if item[:tt_skip] == true

    script_vars.each do |value|
      next unless item[value].nil?

      setted = false
      @stats[:sets].each do |assign|
        setted = true if assign.include?(":#{value}=")
      end

      unless setted
        text = "  * Define '#{value}' value for Case[#{index}] or set tt_skip = true"
        Logger.error text
      end
    end
  end
end

#show_statsObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/teuton/check/show.rb', line 54

def show_stats
  my_screen_table = Terminal::Table.new do |st|
    st.add_row ["DSL Stats", "Count"]
    st.add_separator

    if Project.value[:uses].size.positive?
      st.add_row ["Uses", Project.value[:uses].size]
    end
    if Project.value[:macros].size.positive?
      st.add_row ["Macros", Project.value[:macros].size]
      Project.value[:macros].each_key { st.add_row ["", _1] }
    end
    st.add_row ["Groups", @stats[:groups]]
    st.add_row ["Targets", @stats[:targets]]
    runs = @stats[:hosts].values.inject(0) { |acc, item| acc + item }
    st.add_row ["Runs", runs]
    @stats[:hosts].each_pair { |k, v| st.add_row [" * #{k}", v] }
    if @stats[:uniques].positive?
      st.add_row ["Uniques", @stats[:uniques]]
    end
    if @stats[:logs].positive?
      st.add_row ["Logs", @stats[:logs]]
    end
    if @stats[:readmes].positive?
      st.add_row ["Readmes", @stats[:readmes]]
    end

    if @stats[:gets].size.positive?
      total = @stats[:gets].values.inject(0) { |acc, value| acc + value }
      st.add_row ["Gets", total]
      list = @stats[:gets].sort_by { |_k, v| v }
      list.reverse_each { |item| st.add_row [" * #{item[0]}", item[1].to_s] }
    end

    if @stats[:sets].size.positive?
      st.add_row ["Sets", @stats[:sets].size]
      @stats[:sets].each { st.add_row ["", _1] }
    end
    if @stats[:uploads].size.positive?
      st.add_row ["Uploads", @stats[:uploads].size]
      @stats[:uploads].each { st.add_row ["", _1] }
    end
  end
  Logger.info my_screen_table.to_s + "\n"
end

#suggest_config_contentObject



14
15
16
17
18
19
# File 'lib/teuton/check/show.rb', line 14

def suggest_config_content
  output = {"global" => nil, "cases" => [{}]}
  script_vars = find_script_vars
  script_vars.each { |i| output["cases"][0][i.to_s] = "VALUE" }
  Logger.info YAML.dump(output)
end