Class: Goodcheck::Commands::Pattern

Inherits:
Object
  • Object
show all
Includes:
ConfigLoading, ExitStatus, HomePath
Defined in:
lib/goodcheck/commands/pattern.rb

Constant Summary

Constants included from ExitStatus

ExitStatus::EXIT_ERROR, ExitStatus::EXIT_MATCH, ExitStatus::EXIT_SUCCESS, ExitStatus::EXIT_TEST_FAILED

Instance Attribute Summary collapse

Attributes included from ConfigLoading

#config

Instance Method Summary collapse

Methods included from HomePath

#cache_dir_path

Methods included from ConfigLoading

#handle_config_errors, #load_config!

Constructor Details

#initialize(stdout:, stderr:, path:, ids:, home_path:) ⇒ Pattern

Returns a new instance of Pattern.



14
15
16
17
18
19
20
# File 'lib/goodcheck/commands/pattern.rb', line 14

def initialize(stdout:, stderr:, path:, ids:, home_path:)
  @stdout = stdout
  @stderr = stderr
  @config_path = path
  @ids = ids
  @home_path = home_path
end

Instance Attribute Details

#config_pathObject (readonly)

Returns the value of attribute config_path.



6
7
8
# File 'lib/goodcheck/commands/pattern.rb', line 6

def config_path
  @config_path
end

#home_pathObject (readonly)

Returns the value of attribute home_path.



8
9
10
# File 'lib/goodcheck/commands/pattern.rb', line 8

def home_path
  @home_path
end

#idsObject (readonly)

Returns the value of attribute ids.



7
8
9
# File 'lib/goodcheck/commands/pattern.rb', line 7

def ids
  @ids
end

#stderrObject (readonly)

Returns the value of attribute stderr.



5
6
7
# File 'lib/goodcheck/commands/pattern.rb', line 5

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



4
5
6
# File 'lib/goodcheck/commands/pattern.rb', line 4

def stdout
  @stdout
end

Instance Method Details

#runObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/goodcheck/commands/pattern.rb', line 22

def run
  handle_config_errors stderr do
    load_config!(cache_path: cache_dir_path, force_download: true)

    config.rules.each do |rule|
      if ids.empty? || ids.any? {|pat| pat == rule.id || rule.id.start_with?("#{pat}.") }
        stdout.puts "#{rule.id}:"
        rule.triggers.each do |trigger|
          trigger.patterns.each do |pattern|
            stdout.puts "  - #{pattern.regexp.inspect}"
          end
        end
      end
    end
  end

  EXIT_SUCCESS
end