Class: Npmdc::Checker
- Inherits:
-
Object
- Object
- Npmdc::Checker
- Extended by:
- Forwardable
- Includes:
- Errors
- Defined in:
- lib/npmdc/checker.rb
Constant Summary collapse
- DEPENDENCIES =
%w(dependencies devDependencies).freeze
Instance Attribute Summary collapse
-
#formatter ⇒ Object
Returns the value of attribute formatter.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(options) ⇒ Checker
constructor
A new instance of Checker.
Constructor Details
Instance Attribute Details
#formatter ⇒ Object
Returns the value of attribute formatter.
13 14 15 |
# File 'lib/npmdc/checker.rb', line 13 def formatter @formatter end |
#path ⇒ Object
Returns the value of attribute path.
13 14 15 |
# File 'lib/npmdc/checker.rb', line 13 def path @path end |
Instance Method Details
#call ⇒ Object
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 60 61 62 63 64 65 |
# File 'lib/npmdc/checker.rb', line 26 def call begin success = false package_json_data = package_json(@path) DEPENDENCIES.each do |dep| if package_json_data[dep] begin check_dependencies(package_json_data[dep], dep) end end 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 !@missed_dependencies.empty? ensure if !@missed_dependencies.empty? output("Following dependencies required by your package.json file are missing or not installed properly:") @missed_dependencies.uniq.each do |dep| output(" * #{dep}") end output("\nRun `npm install` to install #{@missed_dependencies.uniq.count} missed packages.", :warn) elsif success output("#{pluralize(@dependencies_count, 'package')} checked. Everything is ok.", :success) end return success end end |