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.
7 8 9 |
# File 'lib/licensed/command/cache.rb', line 7 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/licensed/command/cache.rb', line 5 def config @config end |
Instance Method Details
#run(force: false) ⇒ Object
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/licensed/command/cache.rb', line 11 def run(force: false) summary = @config.apps.flat_map do |app| app_name = app["name"] @config.ui.info "Caching licenes for #{app_name}:" # load the app environment Dir.chdir app.source_path do # map each available app source to it's dependencies app.sources.map do |source| @config.ui.info " #{source.type} dependencies:" names = [] cache_path = app.cache_path.join(source.type) # exclude ignored dependencies dependencies = source.dependencies.select { |d| !app.ignored?(d) } # ensure each dependency is cached dependencies.each do |dependency| name = dependency["name"] version = dependency["version"] names << name filename = cache_path.join("#{name}.txt") if File.exist?(filename) license = Licensed::License.read(filename) # Version did not change, no need to re-cache if !force && version == license["version"] @config.ui.info " Using #{name} (#{version})" next end end @config.ui.info " Caching #{name} (#{version})" dependency.detect_license! dependency.save(filename) end # Clean up cached files that dont match current dependencies Dir.glob(cache_path.join("**/*.txt")).each do |file| file_path = Pathname.new(file) relative_path = file_path.relative_path_from(cache_path).to_s FileUtils.rm(file) unless names.include?(relative_path.chomp(".txt")) end "* #{app_name} #{source.type} dependencies: #{dependencies.size}" end end end @config.ui.confirm "License caching complete!" summary.each do || @config.ui.confirm end end |
#success? ⇒ Boolean
71 72 73 |
# File 'lib/licensed/command/cache.rb', line 71 def success? true end |