lib/bibliothecary/parsers/elm.rb in bibliothecary-4.0.4 vs lib/bibliothecary/parsers/elm.rb in bibliothecary-5.0.0
- old
+ new
@@ -3,63 +3,23 @@
module Bibliothecary
module Parsers
class Elm
include Bibliothecary::Analyser
- def self.parse(filename, path)
- if filename.match(/^elm-package\.json$|^elm_dependencies\.json$/)
- file_contents = File.open(path).read
- json = JSON.parse file_contents
- parse_json_manifest(json)
- elsif filename.match(/^elm-stuff\/exact-dependencies\.json$/)
- file_contents = File.open(path).read
- json = JSON.parse file_contents
- parse_json_lock(json)
- else
- []
- end
- end
-
- def self.analyse(folder_path, file_list)
- [analyse_json(folder_path, file_list),
- analyse_json_lock(folder_path, file_list)]
- end
-
- def self.analyse_json(folder_path, file_list)
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^elm-package\.json$|^elm_dependencies\.json$/) }
- return unless path
-
- manifest = JSON.parse File.open(path).read
-
+ def self.mapping
{
- platform: PLATFORM_NAME,
- path: path,
- dependencies: parse_json_manifest(manifest)
+ /^elm-package\.json$|^elm_dependencies\.json$/ => :parse_json_manifest,
+ /^elm-stuff\/exact-dependencies\.json$/ => :parse_json_lock
}
- rescue
- []
end
- def self.analyse_json_lock(folder_path, file_list)
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^elm-stuff\/exact-dependencies\.json$/) }
- return unless path
-
- manifest = JSON.parse File.open(path).read
-
- {
- platform: PLATFORM_NAME,
- path: path,
- dependencies: parse_json_lock(manifest)
- }
- rescue
- []
- end
-
- def self.parse_json_manifest(manifest)
+ def self.parse_json_manifest(file_contents)
+ manifest = JSON.parse file_contents
map_dependencies(manifest, 'dependencies', 'runtime')
end
- def self.parse_json_lock(manifest)
+ def self.parse_json_lock(file_contents)
+ manifest = JSON.parse file_contents
manifest.map do |name, requirement|
{
name: name,
requirement: requirement,
type: 'runtime'