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.
14 15 16 17 18 19 20 |
# File 'lib/npmdc/checker.rb', line 14 def initialize() @path = .fetch('path', Npmdc.config.path) @types = .fetch('types', Npmdc.config.types) @formatter = Npmdc::Formatter.() @dependencies_count = 0 @missing_dependencies = Set.new end |
Instance Attribute Details
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
12 13 14 |
# File 'lib/npmdc/checker.rb', line 12 def formatter @formatter end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
12 13 14 |
# File 'lib/npmdc/checker.rb', line 12 def path @path end |
#types ⇒ Object (readonly)
Returns the value of attribute types.
12 13 14 |
# File 'lib/npmdc/checker.rb', line 12 def types @types end |
Instance Method Details
#call ⇒ Object
24 25 26 27 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 54 55 56 57 58 59 |
# File 'lib/npmdc/checker.rb', line 24 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 NoNodeModulesError => e output("Failed! Can't find `node_modules` folder inside '#{e.}' directory!") output("\nRun `npm install` to install missing packages.", :warn) rescue WrongPathError => e output("There is no '#{e.}' directory.") rescue MissedPackageError => e output("There is no `package.json` file inside '#{e.}' directory.") rescue JsonParseError => e output("Can't parse JSON file #{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 |