Class: Bibliothecary::Parsers::Go
- Inherits:
-
Object
- Object
- Bibliothecary::Parsers::Go
- Includes:
- Analyser
- Defined in:
- lib/bibliothecary/parsers/go.rb
Constant Summary collapse
- GPM_REGEXP =
/^(.+)\s+(.+)$/
Class Method Summary collapse
- .map_dependencies(manifest, attr_name, dep_attr_name, version_attr_name, type) ⇒ Object
- .mapping ⇒ Object
- .parse_gb_manifest(file_contents) ⇒ Object
- .parse_glide_lockfile(file_contents) ⇒ Object
- .parse_glide_yaml(file_contents) ⇒ Object
- .parse_godep_json(file_contents) ⇒ Object
- .parse_govendor(file_contents) ⇒ Object
- .parse_gpm(file_contents) ⇒ Object
Methods included from Analyser
Class Method Details
.map_dependencies(manifest, attr_name, dep_attr_name, version_attr_name, type) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/bibliothecary/parsers/go.rb', line 80 def self.map_dependencies(manifest, attr_name, dep_attr_name, version_attr_name, type) manifest.fetch(attr_name,[]).map do |dependency| { name: dependency[dep_attr_name], requirement: dependency[version_attr_name] || '*', type: type } end end |
.mapping ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bibliothecary/parsers/go.rb', line 11 def self.mapping { /^glide\.yaml$/ => { kind: 'manifest', parser: :parse_glide_yaml }, /^glide\.lock$/ => { kind: 'lockfile', parser: :parse_glide_lockfile }, /^Godeps\/Godeps\.json$/ => { kind: 'manifest', parser: :parse_godep_json }, /^Godeps$/i => { kind: 'manifest', parser: :parse_gpm }, /^vendor\/manifest$/ => { kind: 'manifest', parser: :parse_gb_manifest }, /^vendor\/vendor.json$/ => { kind: 'manifest', parser: :parse_govendor } } end |
.parse_gb_manifest(file_contents) ⇒ Object
75 76 77 78 |
# File 'lib/bibliothecary/parsers/go.rb', line 75 def self.parse_gb_manifest(file_contents) manifest = JSON.parse file_contents map_dependencies(manifest, 'dependencies', 'importpath', 'revision', 'runtime') end |
.parse_glide_lockfile(file_contents) ⇒ Object
70 71 72 73 |
# File 'lib/bibliothecary/parsers/go.rb', line 70 def self.parse_glide_lockfile(file_contents) manifest = YAML.load file_contents map_dependencies(manifest, 'imports', 'name', 'version', 'runtime') end |
.parse_glide_yaml(file_contents) ⇒ Object
64 65 66 67 68 |
# File 'lib/bibliothecary/parsers/go.rb', line 64 def self.parse_glide_yaml(file_contents) manifest = YAML.load file_contents map_dependencies(manifest, 'import', 'package', 'version', 'runtime') + map_dependencies(manifest, 'devImports', 'package', 'version', 'development') end |
.parse_godep_json(file_contents) ⇒ Object
40 41 42 43 |
# File 'lib/bibliothecary/parsers/go.rb', line 40 def self.parse_godep_json(file_contents) manifest = JSON.parse file_contents map_dependencies(manifest, 'Deps', 'ImportPath', 'Rev', 'runtime') end |
.parse_govendor(file_contents) ⇒ Object
59 60 61 62 |
# File 'lib/bibliothecary/parsers/go.rb', line 59 def self.parse_govendor(file_contents) manifest = JSON.load file_contents map_dependencies(manifest, 'package', 'path', 'revision', 'runtime') end |
.parse_gpm(file_contents) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/bibliothecary/parsers/go.rb', line 45 def self.parse_gpm(file_contents) deps = [] file_contents.split("\n").each do |line| match = line.gsub(/(\#(.*))/, '').match(GPM_REGEXP) next unless match deps << { name: match[1].strip, requirement: match[2].strip || '*', type: 'runtime' } end deps end |