Class: Bibliothecary::Parsers::Dub
- Inherits:
-
Object
- Object
- Bibliothecary::Parsers::Dub
- Defined in:
- lib/bibliothecary/parsers/dub.rb
Constant Summary collapse
- PLATFORM_NAME =
'dub'
Class Method Summary collapse
- .analyse_json(folder_path, file_list) ⇒ Object
- .analyse_sdl(folder_path, file_list) ⇒ Object
- .map_dependencies(hash, key, type) ⇒ Object
- .parse(filename, file_contents) ⇒ Object
- .parse_manifest(manifest) ⇒ Object
- .parse_sdl_manifest(manifest) ⇒ Object
Class Method Details
.analyse_json(folder_path, file_list) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bibliothecary/parsers/dub.rb', line 20 def self.analyse_json(folder_path, file_list) path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^dub\.json$/) } return unless path manifest = JSON.parse File.open(path).read { platform: PLATFORM_NAME, path: path, dependencies: parse_manifest(manifest) } end |
.analyse_sdl(folder_path, file_list) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bibliothecary/parsers/dub.rb', line 33 def self.analyse_sdl(folder_path, file_list) path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^dub\.sdl$/) } return unless path manifest = File.open(path).read { platform: PLATFORM_NAME, path: path, dependencies: parse_sdl_manifest(manifest) } end |
.map_dependencies(hash, key, type) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/bibliothecary/parsers/dub.rb', line 54 def self.map_dependencies(hash, key, type) hash.fetch(key,[]).map do |name, requirement| { name: name, requirement: requirement, type: type } end end |
.parse(filename, file_contents) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/bibliothecary/parsers/dub.rb', line 9 def self.parse(filename, file_contents) if filename.match(/^dub\.json$/) json = JSON.parse(file_contents) parse_manifest(json) elsif filename.match(/^dub\.sdl$/) parse_sdl_manifest(file_contents) else [] end end |
.parse_manifest(manifest) ⇒ Object
46 47 48 |
# File 'lib/bibliothecary/parsers/dub.rb', line 46 def self.parse_manifest(manifest) map_dependencies(manifest, 'dependencies', 'runtime') end |
.parse_sdl_manifest(manifest) ⇒ Object
50 51 52 |
# File 'lib/bibliothecary/parsers/dub.rb', line 50 def self.parse_sdl_manifest(manifest) SdlParser.new(:runtime, manifest).dependencies end |