bibliothecary 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/Gemfile +0 -2
  4. data/bibliothecary.gemspec +1 -1
  5. data/lib/bibliothecary.rb +5 -20
  6. data/lib/bibliothecary/parsers/bower.rb +46 -0
  7. data/lib/bibliothecary/parsers/cargo.rb +71 -0
  8. data/lib/bibliothecary/{carthage.rb → parsers/carthage.rb} +0 -0
  9. data/lib/bibliothecary/{clojars.rb → parsers/clojars.rb} +0 -0
  10. data/lib/bibliothecary/parsers/cocoapods.rb +98 -0
  11. data/lib/bibliothecary/parsers/cpan.rb +73 -0
  12. data/lib/bibliothecary/{dub.rb → parsers/dub.rb} +0 -0
  13. data/lib/bibliothecary/{elm.rb → parsers/elm.rb} +0 -0
  14. data/lib/bibliothecary/{go.rb → parsers/go.rb} +0 -0
  15. data/lib/bibliothecary/{hex.rb → parsers/hex.rb} +0 -0
  16. data/lib/bibliothecary/{julia.rb → parsers/julia.rb} +0 -0
  17. data/lib/bibliothecary/{maven.rb → parsers/maven.rb} +0 -0
  18. data/lib/bibliothecary/parsers/meteor.rb +45 -0
  19. data/lib/bibliothecary/parsers/npm.rb +76 -0
  20. data/lib/bibliothecary/{nuget.rb → parsers/nuget.rb} +0 -0
  21. data/lib/bibliothecary/parsers/packagist.rb +76 -0
  22. data/lib/bibliothecary/parsers/pub.rb +78 -0
  23. data/lib/bibliothecary/{pypi.rb → parsers/pypi.rb} +0 -0
  24. data/lib/bibliothecary/parsers/rubygems.rb +96 -0
  25. data/lib/bibliothecary/version.rb +1 -1
  26. metadata +22 -22
  27. data/lib/bibliothecary/bower.rb +0 -33
  28. data/lib/bibliothecary/cargo.rb +0 -56
  29. data/lib/bibliothecary/cocoapods.rb +0 -78
  30. data/lib/bibliothecary/cpan.rb +0 -57
  31. data/lib/bibliothecary/meteor.rb +0 -32
  32. data/lib/bibliothecary/npm.rb +0 -61
  33. data/lib/bibliothecary/packagist.rb +0 -61
  34. data/lib/bibliothecary/pub.rb +0 -63
  35. data/lib/bibliothecary/rubygems.rb +0 -79
@@ -0,0 +1,76 @@
1
+ require 'json'
2
+
3
+ module Bibliothecary
4
+ module Parsers
5
+ class Packagist
6
+ PLATFORM_NAME = 'Packagist'
7
+
8
+ def self.parse(filename, file_contents)
9
+ json = JSON.parse(file_contents)
10
+ if filename.match(/^composer\.json$/)
11
+ parse_manifest(json)
12
+ elsif filename.match(/^composer\.lock$/)
13
+ parse_lockfile(json)
14
+ else
15
+ []
16
+ end
17
+ end
18
+
19
+ def self.analyse(folder_path, file_list)
20
+ [analyse_composer_json(folder_path, file_list),
21
+ analyse_composer_lock(folder_path, file_list)]
22
+ end
23
+
24
+ def self.analyse_composer_json(folder_path, file_list)
25
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^composer\.json$/) }
26
+ return unless path
27
+
28
+ manifest = JSON.parse File.open(path).read
29
+
30
+ {
31
+ platform: PLATFORM_NAME,
32
+ path: path,
33
+ dependencies: parse_manifest(manifest)
34
+ }
35
+ end
36
+
37
+ def self.analyse_composer_lock(folder_path, file_list)
38
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^composer\.lock$/) }
39
+ return unless path
40
+
41
+ manifest = JSON.parse File.open(path).read
42
+
43
+ {
44
+ platform: PLATFORM_NAME,
45
+ path: path,
46
+ dependencies: parse_lockfile(manifest)
47
+ }
48
+ end
49
+
50
+ def self.parse_lockfile(manifest)
51
+ manifest.fetch('packages',[]).map do |dependency|
52
+ {
53
+ name: dependency["name"],
54
+ requirement: dependency["version"],
55
+ type: 'runtime'
56
+ }
57
+ end
58
+ end
59
+
60
+ def self.parse_manifest(manifest)
61
+ map_dependencies(manifest, 'require', 'runtime') +
62
+ map_dependencies(manifest, 'require-dev', 'development')
63
+ end
64
+
65
+ def self.map_dependencies(hash, key, type)
66
+ hash.fetch(key,[]).map do |name, requirement|
67
+ {
68
+ name: name,
69
+ requirement: requirement,
70
+ type: type
71
+ }
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,78 @@
1
+ require 'yaml'
2
+
3
+ module Bibliothecary
4
+ module Parsers
5
+ class Pub
6
+ PLATFORM_NAME = 'Pub'
7
+
8
+ def self.parse(filename, file_contents)
9
+ yaml = YAML.load file_contents
10
+ if filename.match(/^pubspec\.yaml$/i)
11
+ parse_yaml_manifest(yaml)
12
+ elsif filename.match(/^pubspec\.lock$/i)
13
+ parse_yaml_lockfile(yaml)
14
+ else
15
+ []
16
+ end
17
+ end
18
+
19
+ def self.analyse(folder_path, file_list)
20
+ [
21
+ analyse_yaml(folder_path, file_list),
22
+ analyse_lockfile(folder_path, file_list)
23
+ ]
24
+ end
25
+
26
+ def self.analyse_yaml(folder_path, file_list)
27
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^pubspec\.yaml$/i) }
28
+ return unless path
29
+
30
+ manifest = YAML.load File.open(path).read
31
+
32
+ {
33
+ platform: PLATFORM_NAME,
34
+ path: path,
35
+ dependencies: parse_yaml_manifest(manifest)
36
+ }
37
+ end
38
+
39
+ def self.analyse_lockfile(folder_path, file_list)
40
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^pubspec\.lock$/i) }
41
+ return unless path
42
+
43
+ manifest = YAML.load File.open(path).read
44
+
45
+ {
46
+ platform: PLATFORM_NAME,
47
+ path: path,
48
+ dependencies: parse_yaml_lockfile(manifest)
49
+ }
50
+ end
51
+
52
+ def self.parse_yaml_manifest(manifest)
53
+ map_dependencies(manifest, 'dependencies', 'runtime') +
54
+ map_dependencies(manifest, 'dev_dependencies', 'development')
55
+ end
56
+
57
+ def self.parse_yaml_lockfile(manifest)
58
+ manifest.fetch('packages', []).map do |name, dep|
59
+ {
60
+ name: name,
61
+ requirement: dep['version'],
62
+ type: 'runtime'
63
+ }
64
+ end
65
+ end
66
+
67
+ def self.map_dependencies(hash, key, type)
68
+ hash.fetch(key,[]).map do |name, requirement|
69
+ {
70
+ name: name,
71
+ requirement: requirement,
72
+ type: type
73
+ }
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,96 @@
1
+ require 'gemnasium/parser'
2
+
3
+ module Bibliothecary
4
+ module Parsers
5
+ class Rubygems
6
+ NAME_VERSION = '(?! )(.*?)(?: \(([^-]*)(?:-(.*))?\))?'.freeze
7
+ NAME_VERSION_4 = /^ {4}#{NAME_VERSION}$/
8
+ PLATFORM_NAME = 'Rubygems'
9
+
10
+ def self.parse(filename, file_contents)
11
+ if filename.match(/^Gemfile$|^gems\.rb$/)
12
+ manifest = Gemnasium::Parser.send(:gemfile, file_contents)
13
+ parse_manifest(manifest)
14
+ elsif filename.match(/^[A-Za-z0-9_-]+\.gemspec$/)
15
+ manifest = Gemnasium::Parser.send(:gemspec, file_contents)
16
+ parse_manifest(manifest)
17
+ elsif filename.match(/^Gemfile\.lock$|^gems\.locked$/)
18
+ parse_gemfile_lock(file_contents)
19
+ else
20
+ []
21
+ end
22
+ end
23
+
24
+ def self.analyse(folder_path, file_list)
25
+ [
26
+ analyse_gemfile(folder_path, file_list),
27
+ analyse_gemspec(folder_path, file_list),
28
+ analyse_gemfile_lock(folder_path, file_list)
29
+ ]
30
+ end
31
+
32
+ def self.analyse_gemfile(folder_path, file_list)
33
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^Gemfile$|^gems\.rb$/) }
34
+ return unless path
35
+
36
+ manifest = Gemnasium::Parser.send(:gemfile, File.open(path).read)
37
+
38
+ {
39
+ platform: PLATFORM_NAME,
40
+ path: path,
41
+ dependencies: parse_manifest(manifest)
42
+ }
43
+ end
44
+
45
+ def self.analyse_gemspec(folder_path, file_list)
46
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^[A-Za-z0-9_-]+\.gemspec$/) }
47
+ return unless path
48
+
49
+ manifest = Gemnasium::Parser.send(:gemspec, File.open(path).read)
50
+
51
+ {
52
+ platform: PLATFORM_NAME,
53
+ path: path,
54
+ dependencies: parse_manifest(manifest)
55
+ }
56
+ end
57
+
58
+ def self.analyse_gemfile_lock(folder_path, file_list)
59
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^Gemfile\.lock$|^gems\.locked$/) }
60
+ return unless path
61
+
62
+ manifest = File.open(path).read
63
+
64
+ {
65
+ platform: PLATFORM_NAME,
66
+ path: path,
67
+ dependencies: parse_gemfile_lock(manifest)
68
+ }
69
+ end
70
+
71
+ def self.parse_gemfile_lock(manifest)
72
+ manifest.split("\n").map do |line|
73
+ match = line.match(NAME_VERSION_4)
74
+ next unless match
75
+ name = match[1]
76
+ version = match[2].gsub(/\(|\)/,'')
77
+ {
78
+ name: name,
79
+ requirement: version,
80
+ type: 'runtime'
81
+ }
82
+ end.compact
83
+ end
84
+
85
+ def self.parse_manifest(manifest)
86
+ manifest.dependencies.inject([]) do |deps, dep|
87
+ deps.push({
88
+ name: dep.name,
89
+ requirement: dep.requirement.to_s,
90
+ type: dep.type
91
+ })
92
+ end.uniq
93
+ end
94
+ end
95
+ end
96
+ end
@@ -1,3 +1,3 @@
1
1
  module Bibliothecary
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bibliothecary
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Nesbitt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-24 00:00:00.000000000 Z
11
+ date: 2016-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: toml-rb
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.3.9
27
27
  - !ruby/object:Gem::Dependency
28
- name: gemnasium-parser
28
+ name: librariesio-gem-parser
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -100,25 +100,25 @@ files:
100
100
  - bin/console
101
101
  - bin/setup
102
102
  - lib/bibliothecary.rb
103
- - lib/bibliothecary/bower.rb
104
- - lib/bibliothecary/cargo.rb
105
- - lib/bibliothecary/carthage.rb
106
- - lib/bibliothecary/clojars.rb
107
- - lib/bibliothecary/cocoapods.rb
108
- - lib/bibliothecary/cpan.rb
109
- - lib/bibliothecary/dub.rb
110
- - lib/bibliothecary/elm.rb
111
- - lib/bibliothecary/go.rb
112
- - lib/bibliothecary/hex.rb
113
- - lib/bibliothecary/julia.rb
114
- - lib/bibliothecary/maven.rb
115
- - lib/bibliothecary/meteor.rb
116
- - lib/bibliothecary/npm.rb
117
- - lib/bibliothecary/nuget.rb
118
- - lib/bibliothecary/packagist.rb
119
- - lib/bibliothecary/pub.rb
120
- - lib/bibliothecary/pypi.rb
121
- - lib/bibliothecary/rubygems.rb
103
+ - lib/bibliothecary/parsers/bower.rb
104
+ - lib/bibliothecary/parsers/cargo.rb
105
+ - lib/bibliothecary/parsers/carthage.rb
106
+ - lib/bibliothecary/parsers/clojars.rb
107
+ - lib/bibliothecary/parsers/cocoapods.rb
108
+ - lib/bibliothecary/parsers/cpan.rb
109
+ - lib/bibliothecary/parsers/dub.rb
110
+ - lib/bibliothecary/parsers/elm.rb
111
+ - lib/bibliothecary/parsers/go.rb
112
+ - lib/bibliothecary/parsers/hex.rb
113
+ - lib/bibliothecary/parsers/julia.rb
114
+ - lib/bibliothecary/parsers/maven.rb
115
+ - lib/bibliothecary/parsers/meteor.rb
116
+ - lib/bibliothecary/parsers/npm.rb
117
+ - lib/bibliothecary/parsers/nuget.rb
118
+ - lib/bibliothecary/parsers/packagist.rb
119
+ - lib/bibliothecary/parsers/pub.rb
120
+ - lib/bibliothecary/parsers/pypi.rb
121
+ - lib/bibliothecary/parsers/rubygems.rb
122
122
  - lib/bibliothecary/version.rb
123
123
  homepage: https://github.com/librariesio/bibliothecary
124
124
  licenses:
@@ -1,33 +0,0 @@
1
- require 'json'
2
-
3
- module Bibliothecary
4
- class Bower
5
- def self.analyse(folder_path, file_list)
6
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^bower\.json$/) }
7
- return unless path
8
-
9
- manifest = JSON.parse File.open(path).read
10
-
11
- {
12
- platform: 'bower',
13
- path: path,
14
- dependencies: parse_manifest(manifest)
15
- }
16
- end
17
-
18
- def self.parse_manifest(manifest)
19
- map_dependencies(manifest, 'dependencies', 'runtime') +
20
- map_dependencies(manifest, 'devDependencies', 'development')
21
- end
22
-
23
- def self.map_dependencies(hash, key, type)
24
- hash.fetch(key,[]).map do |name, requirement|
25
- {
26
- name: name,
27
- requirement: requirement,
28
- type: type
29
- }
30
- end
31
- end
32
- end
33
- end
@@ -1,56 +0,0 @@
1
- require 'toml'
2
-
3
- module Bibliothecary
4
- class Cargo
5
- def self.analyse(folder_path, file_list)
6
- [analyse_cargo_toml(folder_path, file_list),
7
- analyse_cargo_lock(folder_path, file_list)]
8
- end
9
-
10
- def self.analyse_cargo_toml(folder_path, file_list)
11
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^Cargo\.toml$/) }
12
- return unless path
13
-
14
- manifest = TOML.load_file(path)
15
-
16
- {
17
- platform: 'cargo',
18
- path: path,
19
- dependencies: parse_manifest(manifest)
20
- }
21
- end
22
-
23
- def self.parse_manifest(manifest)
24
- manifest.fetch('dependencies', []).map do |name, requirement|
25
- {
26
- name: name,
27
- requirement: requirement,
28
- type: 'runtime'
29
- }
30
- end
31
- end
32
-
33
- def self.analyse_cargo_lock(folder_path, file_list)
34
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^Cargo\.lock$/) }
35
- return unless path
36
-
37
- manifest = TOML.load_file(path)
38
-
39
- {
40
- platform: 'cargo',
41
- path: path,
42
- dependencies: parse_lockfile(manifest)
43
- }
44
- end
45
-
46
- def self.parse_lockfile(manifest)
47
- manifest.fetch('package',[]).map do |dependency|
48
- {
49
- name: dependency['name'],
50
- requirement: dependency['version'],
51
- type: 'runtime'
52
- }
53
- end
54
- end
55
- end
56
- end
@@ -1,78 +0,0 @@
1
- require 'gemnasium/parser'
2
- require 'yaml'
3
-
4
- module Bibliothecary
5
- class CocoaPods
6
- NAME_VERSION = '(?! )(.*?)(?: \(([^-]*)(?:-(.*))?\))?'.freeze
7
- NAME_VERSION_4 = /^ {4}#{NAME_VERSION}$/
8
-
9
- def self.analyse(folder_path, file_list)
10
- [
11
- analyse_podfile(folder_path, file_list),
12
- analyse_podspec(folder_path, file_list),
13
- analyse_podfile_lock(folder_path, file_list)
14
- ]
15
- end
16
-
17
- def self.analyse_podfile(folder_path, file_list)
18
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^Podfile$/) }
19
- return unless path
20
-
21
- manifest = Gemnasium::Parser.send(:podfile, File.open(path).read)
22
-
23
- {
24
- platform: 'CocoaPods',
25
- path: path,
26
- dependencies: parse_manifest(manifest)
27
- }
28
- end
29
-
30
- def self.analyse_podspec(folder_path, file_list)
31
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^[A-Za-z0-9_-]+\.podspec$/) }
32
- return unless path
33
-
34
- manifest = Gemnasium::Parser.send(:podspec, File.open(path).read)
35
-
36
- {
37
- platform: 'CocoaPods',
38
- path: path,
39
- dependencies: parse_manifest(manifest)
40
- }
41
- end
42
-
43
- def self.analyse_podfile_lock(folder_path, file_list)
44
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^Podfile\.lock$/) }
45
- return unless path
46
-
47
- manifest = YAML.load File.open(path).read
48
-
49
- {
50
- platform: 'CocoaPods',
51
- path: path,
52
- dependencies: parse_podfile_lock(manifest)
53
- }
54
- end
55
-
56
- def self.parse_podfile_lock(manifest)
57
- manifest['PODS'].map do |row|
58
- pod = row.is_a?(String) ? row : row.keys.first
59
- match = pod.match(/(.+?)\s\((.+?)\)/i)
60
- {
61
- name: match[1].split('/').first,
62
- requirement: match[2],
63
- type: 'runtime'
64
- }
65
- end.compact
66
- end
67
-
68
- def self.parse_manifest(manifest)
69
- manifest.dependencies.inject([]) do |deps, dep|
70
- deps.push({
71
- name: dep.name,
72
- requirement: dep.requirement.to_s,
73
- type: dep.type
74
- })
75
- end.uniq
76
- end
77
- end
78
- end