Class: Licensed::Command::Verify
- Inherits:
-
Object
- Object
- Licensed::Command::Verify
- Defined in:
- lib/licensed/command/verify.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #approved?(dependency) ⇒ Boolean
- #dependencies ⇒ Object
-
#initialize(config) ⇒ Verify
constructor
A new instance of Verify.
- #run ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(config) ⇒ Verify
Returns a new instance of Verify.
8 9 10 |
# File 'lib/licensed/command/verify.rb', line 8 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/licensed/command/verify.rb', line 6 def config @config end |
Instance Method Details
#approved?(dependency) ⇒ Boolean
12 13 14 15 |
# File 'lib/licensed/command/verify.rb', line 12 def approved?(dependency) @config.whitelisted?(dependency) || @config.reviewed?(dependency) end |
#dependencies ⇒ Object
17 18 19 |
# File 'lib/licensed/command/verify.rb', line 17 def dependencies @dependencies ||= @config.sources.map(&:dependencies).flatten end |
#run ⇒ Object
21 22 23 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 60 61 62 63 64 65 |
# File 'lib/licensed/command/verify.rb', line 21 def run @config.ui.info "Verifying licenses for #{dependencies.size} dependencies" @results = dependencies.map do |dependency| next if @config.ignored?(dependency) filename = @config.path.join("#{dependency["type"]}/#{dependency["name"]}.txt") warnings = [] if File.exists?(filename) license = License.read(filename) if license["version"] != dependency["version"] warnings << "cached license data out of date" end warnings << "missing license text" if license.text.strip.empty? unless approved?(license) warnings << "license needs reviewed: #{license["license"]}." end else warnings << "missing license data" end if warnings.size > 0 @config.ui.error("F", false) [filename, warnings] else @config.ui.confirm(".", false) nil end end.compact unless success? @config.ui.warn "\n\nWarnings:" @results.each do |filename, warnings| @config.ui.info "\n#{filename}:" warnings.each do |warning| @config.ui.error " - #{warning}" end end end puts "\n#{dependencies.size} dependencies checked, #{@results.size} warnings found." end |
#success? ⇒ Boolean
67 68 69 |
# File 'lib/licensed/command/verify.rb', line 67 def success? @results.empty? end |