Class: Gemstar::ImportmapFile
- Inherits:
-
Object
- Object
- Gemstar::ImportmapFile
- Defined in:
- lib/gemstar/importmap_file.rb
Defined Under Namespace
Classes: Pin
Constant Summary collapse
- IMPORTMAP_PACKAGE_METADATA_PATH =
File.("data/importmap_package_metadata.json", __dir__)
Instance Attribute Summary collapse
-
#pins ⇒ Object
readonly
Returns the value of attribute pins.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path: nil, content: nil, vendor_reader: nil) ⇒ ImportmapFile
constructor
A new instance of ImportmapFile.
- #source_for(name) ⇒ Object
- #specs ⇒ Object
Constructor Details
#initialize(path: nil, content: nil, vendor_reader: nil) ⇒ ImportmapFile
Returns a new instance of ImportmapFile.
21 22 23 24 25 |
# File 'lib/gemstar/importmap_file.rb', line 21 def initialize(path: nil, content: nil, vendor_reader: nil) @path = path @vendor_reader = vendor_reader @pins = parse_content(content || File.read(path)) end |
Instance Attribute Details
#pins ⇒ Object (readonly)
Returns the value of attribute pins.
27 28 29 |
# File 'lib/gemstar/importmap_file.rb', line 27 def pins @pins end |
Class Method Details
.package_metadata ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/gemstar/importmap_file.rb', line 9 def self. @package_metadata ||= begin JSON.parse(File.read(IMPORTMAP_PACKAGE_METADATA_PATH)).transform_values do |attributes| attributes.each_with_object({}) do |(key, value), | [key.to_sym] = value end end rescue Errno::ENOENT, JSON::ParserError {} end end |
Instance Method Details
#source_for(name) ⇒ Object
33 34 35 |
# File 'lib/gemstar/importmap_file.rb', line 33 def source_for(name) pins[name]&.source end |
#specs ⇒ Object
29 30 31 |
# File 'lib/gemstar/importmap_file.rb', line 29 def specs pins.transform_values(&:target) end |