Class: Marcdouane::FileChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/marcdouane/file_checker.rb

Class Method Summary collapse

Class Method Details

.call(file, options) ⇒ Object



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

def call(file, options)
  verbose = options.fetch(:verbose)

  parse_config!(options[:config])

  puts "Checking `#{file}'..." if verbose

  exit_code = 0

  rules.each do |rule|
    rule.new(file, options).check!
  rescue Marcdouane::Error => e
    $stderr.puts("#{file}:#{e.line_number}: #{e.message}")

    exit_code = 1
  end

  puts "Done." if verbose

  exit_code
end

.parse_config!(path) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/marcdouane/file_checker.rb', line 33

def parse_config!(path)
  return if path.nil?

  config = YAML.load_file(path)

  config.each do |klass, hash|
    hash.each do |key, value|
      rule_class = "Marcdouane::Rules::#{klass}"

      const_get(rule_class).class_eval do
        self.config[key.to_sym] = value
      end
    end
  end
end

.rulesObject



49
50
51
# File 'lib/marcdouane/file_checker.rb', line 49

def rules
  Marcdouane::Rules::Rule.subclasses
end