lib/bibliothecary/parsers/cpan.rb in bibliothecary-4.0.4 vs lib/bibliothecary/parsers/cpan.rb in bibliothecary-5.0.0

- old
+ new

@@ -4,30 +4,25 @@ module Bibliothecary module Parsers class CPAN include Bibliothecary::Analyser - def self.parse(filename, path) - if filename.match(/^META\.json$/i) - file_contents = File.open(path).read - json = JSON.parse file_contents - parse_json_manifest(json) - elsif filename.match(/^META\.yml$/i) - file_contents = File.open(path).read - yaml = YAML.load file_contents - parse_yaml_manifest(yaml) - else - [] - end + def self.mapping + { + /^META\.json$/i => :parse_json_manifest, + /^META\.yml$/i => :parse_yaml_manifest + } end - def self.parse_json_manifest(manifest) - manifest['prereqs'].map do |group, deps| + def self.parse_json_manifest(file_contents) + manifest = JSON.parse file_contents + manifest['prereqs'].map do |_group, deps| map_dependencies(deps, 'requires', 'runtime') end.flatten end - def self.parse_yaml_manifest(manifest) + def self.parse_yaml_manifest(file_contents) + manifest = YAML.load file_contents map_dependencies(manifest, 'requires', 'runtime') end def self.map_dependencies(hash, key, type) hash.fetch(key,[]).map do |name, requirement|