Class: YamlChecker::Checker

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Checker

Returns a new instance of Checker.



14
15
16
# File 'lib/yaml_checker.rb', line 14

def initialize(argv)
  @argv = argv
end

Class Method Details

.run(*args) ⇒ Object



10
11
12
# File 'lib/yaml_checker.rb', line 10

def self.run(*args)
  new(*args).run
end

Instance Method Details

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/yaml_checker.rb', line 18

def run
  if File.directory?(path)
    Dir.glob("#{path}/**/*.{yml,yaml}").each do |f|
      load(f)
      warn errors
      return errors.empty?
    end
  elsif File.file?(path)
    if File.extname(path).match(/\.ya?ml/)
      load(path)
      warn errors
      return errors.empty?
    else
      warn "#{path}: File extname should be .yml or .yaml"
      return false
    end
  else
    warn "#{path}: No such file or directory"
    return false
  end
end