Class: Bibliothecary::Parsers::Go
- Inherits:
-
Object
- Object
- Bibliothecary::Parsers::Go
- Includes:
- Analyser
- Defined in:
- lib/bibliothecary/parsers/go.rb
Class Method Summary collapse
- .parse(filename, path) ⇒ Object
- .parse_gb_manifest(manifest) ⇒ Object
- .parse_glide_lockfile(manifest) ⇒ Object
- .parse_glide_yaml(manifest) ⇒ Object
- .parse_godep_json(manifest) ⇒ Object
Methods included from Analyser
Class Method Details
.parse(filename, path) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bibliothecary/parsers/go.rb', line 9 def self.parse(filename, path) if filename.match(/^glide\.yaml$/) file_contents = File.open(path).read yaml = YAML.load file_contents parse_glide_yaml(yaml) elsif filename.match(/^glide\.lock$/) file_contents = File.open(path).read yaml = YAML.load file_contents parse_glide_lockfile(yaml) elsif filename.match(/^Godeps\/Godeps\.json$/) file_contents = File.open(path).read json = JSON.parse file_contents parse_godep_json(json) elsif filename.match(/^vendor\/manifest$/) file_contents = File.open(path).read json = JSON.parse file_contents parse_gb_manifest(json) else [] end end |
.parse_gb_manifest(manifest) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/bibliothecary/parsers/go.rb', line 67 def self.parse_gb_manifest(manifest) manifest.fetch('dependencies',[]).map do |dependency| { name: dependency['importpath'], requirement: dependency['revision'], type: 'runtime' } end end |
.parse_glide_lockfile(manifest) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/bibliothecary/parsers/go.rb', line 57 def self.parse_glide_lockfile(manifest) manifest.fetch('imports',[]).map do |dependency| { name: dependency['name'], requirement: dependency['version'] || '*', type: 'runtime' } end end |
.parse_glide_yaml(manifest) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/bibliothecary/parsers/go.rb', line 41 def self.parse_glide_yaml(manifest) manifest.fetch('import',[]).map do |dependency| { name: dependency['package'], requirement: dependency['version'] || '*', type: 'runtime' } end + manifest.fetch('devImports',[]).map do |dependency| { name: dependency['package'], requirement: dependency['version'] || '*', type: 'development' } end end |
.parse_godep_json(manifest) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/bibliothecary/parsers/go.rb', line 31 def self.parse_godep_json(manifest) manifest.fetch('Deps',[]).map do |dependency| { name: dependency['ImportPath'], requirement: dependency['Rev'], type: 'runtime' } end end |