Class: Licensed::Command::Cache
- Inherits:
-
Object
- Object
- Licensed::Command::Cache
- Defined in:
- lib/licensed/command/cache.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(config) ⇒ Cache
constructor
A new instance of Cache.
- #run(force: false) ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(config) ⇒ Cache
Returns a new instance of Cache.
6 7 8 |
# File 'lib/licensed/command/cache.rb', line 6 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
4 5 6 |
# File 'lib/licensed/command/cache.rb', line 4 def config @config end |
Instance Method Details
#run(force: false) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 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 |
# File 'lib/licensed/command/cache.rb', line 10 def run(force: false) @config.sources.each do |source| @config.ui.info "Caching licenses for #{source.type} dependencies:" source.dependencies.each do |dependency| next if @config.ignored?(dependency) filename = @config.path.join("#{source.type}/#{dependency["name"]}.txt") if File.exist?(filename) license = Licensed::License.read(filename) # Version did not change, no need to re-cache if !force && dependency["version"] == license["version"] @config.ui.info " Using #{dependency["name"]} (#{dependency["version"]})" next end end @config.ui.info " Caching #{dependency["name"]} (#{dependency["version"]})" dependency.detect_license! dependency.save(filename) end # Clean up dependencies that have been removed names = source.dependencies.map do |dependency| dependency["name"] unless @config.ignored?(dependency) end.compact Dir.glob(@config.path.join("#{source.type}/*.txt")).each do |file| FileUtils.rm(file) unless names.include?(File.basename(file, ".txt")) end end @config.ui.confirm "License caching complete!" @config.sources.each do |source| @config.ui.confirm "* #{source.type} dependencies: #{source.dependencies.size}" end end |
#success? ⇒ Boolean
51 52 53 |
# File 'lib/licensed/command/cache.rb', line 51 def success? true end |