Class: Spandx::Core::Cache
- Inherits:
-
Object
- Object
- Spandx::Core::Cache
- Includes:
- Enumerable
- Defined in:
- lib/spandx/core/cache.rb
Instance Attribute Summary collapse
-
#package_manager ⇒ Object
readonly
Returns the value of attribute package_manager.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #datafile_for(name) ⇒ Object
- #each ⇒ Object
-
#initialize(package_manager, root:) ⇒ Cache
constructor
A new instance of Cache.
- #insert(name, version, licenses) ⇒ Object
- #insert!(*args) ⇒ Object
- #licenses_for(name, version) ⇒ Object
- #rebuild_index ⇒ Object
Constructor Details
Instance Attribute Details
#package_manager ⇒ Object (readonly)
Returns the value of attribute package_manager.
8 9 10 |
# File 'lib/spandx/core/cache.rb', line 8 def package_manager @package_manager end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
8 9 10 |
# File 'lib/spandx/core/cache.rb', line 8 def root @root end |
Instance Method Details
#datafile_for(name) ⇒ Object
42 43 44 |
# File 'lib/spandx/core/cache.rb', line 42 def datafile_for(name) datafiles.fetch(key_for(name)) end |
#each ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/spandx/core/cache.rb', line 23 def each datafiles.each do |_hex, datafile| datafile.each do |item| yield item end end end |
#insert(name, version, licenses) ⇒ Object
31 32 33 34 35 |
# File 'lib/spandx/core/cache.rb', line 31 def insert(name, version, licenses) return if name.nil? || name.empty? datafile_for(name).insert(name, version, licenses) end |
#insert!(*args) ⇒ Object
37 38 39 40 |
# File 'lib/spandx/core/cache.rb', line 37 def insert!(*args) insert(*args) rebuild_index end |
#licenses_for(name, version) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/spandx/core/cache.rb', line 15 def licenses_for(name, version) return [] if name.nil? || name.empty? found = datafile_for(name).search(name: name, version: version) Spandx.logger.debug { "Cache miss: #{name}-#{version}" } unless found found ? found[2].split('-|-') : [] end |
#rebuild_index ⇒ Object
46 47 48 49 50 |
# File 'lib/spandx/core/cache.rb', line 46 def rebuild_index datafiles.each do |_hex, datafile| datafile.index.update! end end |