Class: Npmdc::Checker

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Errors
Defined in:
lib/npmdc/checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Checker

Returns a new instance of Checker.



15
16
17
18
19
20
21
# File 'lib/npmdc/checker.rb', line 15

def initialize(options)
  @path = options.fetch('path', Npmdc.config.path)
  @types = options.fetch('types', Npmdc.config.types)
  @formatter = Npmdc::Formatter.(options)
  @dependencies_count = 0
  @missing_dependencies = Set.new
end

Instance Attribute Details

#formatterObject (readonly)

Returns the value of attribute formatter.



13
14
15
# File 'lib/npmdc/checker.rb', line 13

def formatter
  @formatter
end

#pathObject (readonly)

Returns the value of attribute path.



13
14
15
# File 'lib/npmdc/checker.rb', line 13

def path
  @path
end

#typesObject (readonly)

Returns the value of attribute types.



13
14
15
# File 'lib/npmdc/checker.rb', line 13

def types
  @types
end

Instance Method Details

#callObject



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
53
# File 'lib/npmdc/checker.rb', line 28

def call
  begin
    success = false
    package_json_data = package_json(path)
    @types.each do |dep|
      check_dependencies(package_json_data[dep], dep) if package_json_data[dep]
    end

  rescue CheckerError => e
    error_output(e)
  else
    success = true unless !@missing_dependencies.empty?
  ensure
    if !@missing_dependencies.empty?
      output("Following dependencies required by your package.json file are missing or not installed properly:")
      @missing_dependencies.each do |dep|
        output("  * #{dep}")
      end
      output("\nRun `npm install` to install #{@missing_dependencies.size} missing packages.", :warn)
    elsif success
      output("Checked #{@dependencies_count} packages. Everything is ok.", :success)
    end
  end

  success
end