Class: Spandx::Rubygems::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/spandx/rubygems/index.rb

Constant Summary collapse

COMMON_LICENSES =
['MIT', 'Apache-2.0', 'GPL-3.0', 'LGPL-3.0', 'BSD', 'BSD-3-Clause', 'WFTPL'].freeze

Instance Method Summary collapse

Constructor Details

#initializeIndex

Returns a new instance of Index.



8
9
10
11
# File 'lib/spandx/rubygems/index.rb', line 8

def initialize
  @dir = Spandx::Rubygems.root.join('index')
  @rubygems_file = DataFile.new(Spandx::Rubygems.root.join('rubygems.index'), default: {})
end

Instance Method Details

#eachObject



17
18
19
# File 'lib/spandx/rubygems/index.rb', line 17

def each
  to_h.each { |key, value| yield key, value }
end

#licenses_for(name:, version:) ⇒ Object



13
14
15
# File 'lib/spandx/rubygems/index.rb', line 13

def licenses_for(name:, version:)
  to_h.fetch(index_key_for(name, version), [])
end

#to_hObject



21
22
23
# File 'lib/spandx/rubygems/index.rb', line 21

def to_h
  @rubygems_file.data
end

#update!Object



25
26
27
28
29
# File 'lib/spandx/rubygems/index.rb', line 25

def update!
  update_expanded_index!
  sort_index!
  build_optimized_index!
end