Class: Npmdc::Checker
- Inherits:
-
Object
- Object
- Npmdc::Checker
- Extended by:
- Forwardable
- Includes:
- Errors
- Defined in:
- lib/npmdc/checker.rb
Instance Attribute Summary collapse
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(options) ⇒ Checker
constructor
A new instance of Checker.
Constructor Details
#initialize(options) ⇒ Checker
Returns a new instance of Checker.
15 16 17 18 19 20 21 22 23 |
# File 'lib/npmdc/checker.rb', line 15 def initialize() @path = .fetch('path', Npmdc.config.path) @types = .fetch('types', Npmdc.config.types) @abort_on_failure = .fetch('abort_on_failure', Npmdc.config.abort_on_failure) @formatter = Npmdc::Formatter.() @dependencies_count = 0 @missing_dependencies = Set.new @suspicious_dependencies = Set.new end |
Instance Attribute Details
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
13 14 15 |
# File 'lib/npmdc/checker.rb', line 13 def formatter @formatter end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
13 14 15 |
# File 'lib/npmdc/checker.rb', line 13 def path @path end |
#types ⇒ Object (readonly)
Returns the value of attribute types.
13 14 15 |
# File 'lib/npmdc/checker.rb', line 13 def types @types end |
Instance Method Details
#call ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/npmdc/checker.rb', line 30 def call package_json_data = package_json(path) @types.each do |dep| check_dependencies(package_json_data[dep], dep) if package_json_data[dep] end if !@missing_dependencies.empty? raise(MissedDependencyError, dependencies: @missing_dependencies) end result_stats = "Checked #{@dependencies_count} packages. " + "Warnings: #{@suspicious_dependencies.count}. " + "Errors: #{@missing_dependencies.count}. " + "Everything is ok." output(result_stats, :success) true rescue CheckerError => e error_output(e) exit(1) if @abort_on_failure && e.class.critical? false end |