Class: Licensed::Command::Status
- Inherits:
-
Object
- Object
- Licensed::Command::Status
- Defined in:
- lib/licensed/command/status.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #allowed_or_reviewed?(app, dependency) ⇒ Boolean
- #app_dependencies(app) ⇒ Object
-
#initialize(config) ⇒ Status
constructor
A new instance of Status.
- #run ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(config) ⇒ Status
Returns a new instance of Status.
9 10 11 |
# File 'lib/licensed/command/status.rb', line 9 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/licensed/command/status.rb', line 7 def config @config end |
Instance Method Details
#allowed_or_reviewed?(app, dependency) ⇒ Boolean
13 14 15 |
# File 'lib/licensed/command/status.rb', line 13 def allowed_or_reviewed?(app, dependency) app.allowed?(dependency) || app.reviewed?(dependency) end |
#app_dependencies(app) ⇒ Object
17 18 19 |
# File 'lib/licensed/command/status.rb', line 17 def app_dependencies(app) app.sources.flat_map(&:dependencies).select { |d| !app.ignored?(d) } 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 66 67 68 69 70 71 |
# File 'lib/licensed/command/status.rb', line 21 def run @results = @config.apps.flat_map do |app| Dir.chdir app.source_path do dependencies = app_dependencies(app) @config.ui.info "Checking licenses for #{app['name']}: #{dependencies.size} dependencies" results = dependencies.map do |dependency| filename = app.cache_path.join(dependency["type"], "#{dependency["name"]}.txt") warnings = [] # verify cached license data for dependency if File.exist?(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 allowed_or_reviewed?(app, license) warnings << "license needs reviewed: #{license["license"]}." end else warnings << "cached license data missing" end if warnings.size > 0 @config.ui.error("F", false) [filename, warnings] else @config.ui.confirm(".", false) nil end end.compact unless results.empty? @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." results end end end |
#success? ⇒ Boolean
73 74 75 |
# File 'lib/licensed/command/status.rb', line 73 def success? @results.empty? end |