Sha256: 22aeb43d0550895ccfc9c6aebfe74ee5cd9aaf25d1d7a8f607e4972a72535159
Contents?: true
Size: 1.73 KB
Versions: 10
Compression:
Stored size: 1.73 KB
Contents
require 'json' require 'sdl_parser' module Bibliothecary module Parsers class Dub PLATFORM_NAME = 'dub' 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 def self.analyse(folder_path, file_list) [analyse_json(folder_path, file_list), analyse_sdl(folder_path, file_list)] end 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 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 def self.parse_manifest(manifest) map_dependencies(manifest, 'dependencies', 'runtime') end def self.parse_sdl_manifest(manifest) SdlParser.new(:runtime, manifest).dependencies end def self.map_dependencies(hash, key, type) hash.fetch(key,[]).map do |name, requirement| { name: name, requirement: requirement, type: type } end end end end end
Version data entries
10 entries across 10 versions & 1 rubygems