bibliothecary 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 04a1a8adea070840de3ca6b87c6a56e72b1e6559
4
+ data.tar.gz: 1ca460c71be62e6be28eb8a8c7f8c003e3755940
5
+ SHA512:
6
+ metadata.gz: 221e067f6a618d8044c190e8e118cee3d5bbdddd47400333dffa52cc2f27891ab489160cbb2a543358a68924407239c976f4829375e1a0e66aa19533d0a42ae5
7
+ data.tar.gz: 81cfc2f47e647184b58099471c09344a43c4ae4892c31f359d3d83019ea9a1173ef010261addf0a62747a42ab8c95c902039403ead8b97f1c7b4f60ac3012bf1
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at andrewnez@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bibliothecary.gemspec
4
+ gemspec
5
+
6
+ gem 'gemnasium-parser', github: 'librariesio/gemnasium-parser'
@@ -0,0 +1,33 @@
1
+ # Bibliothecary
2
+
3
+ Dependency manifest parsing service for https://libraries.io in Ruby
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'bibliothecary'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install bibliothecary
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/librariesio/bibliothecary. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bibliothecary/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bibliothecary"
8
+ spec.version = Bibliothecary::VERSION
9
+ spec.authors = ["Andrew Nesbitt"]
10
+ spec.email = ["andrewnez@gmail.com"]
11
+
12
+ spec.summary = "Find and parse manifests"
13
+ spec.homepage = "https://github.com/librariesio/bibliothecary"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "toml-rb", "~> 0.3.9"
21
+ spec.add_dependency "gemnasium-parser"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.11"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bibliothecary"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+ require "bibliothecary/version"
2
+ require "bibliothecary/npm"
3
+ require "bibliothecary/bower"
4
+ require "bibliothecary/packagist"
5
+ require "bibliothecary/cpan"
6
+ require "bibliothecary/meteor"
7
+ require "bibliothecary/cargo"
8
+ require "bibliothecary/pub"
9
+ require "bibliothecary/rubygems"
10
+ require "bibliothecary/cocoapods"
11
+
12
+ module Bibliothecary
13
+ def self.analyse(path)
14
+ cmd = `find #{path} -type f | grep -vE "#{ignored_files}"`
15
+ file_list = cmd.split("\n")
16
+ package_managers.map{|pm| pm.analyse(path, file_list) }.flatten.compact
17
+ end
18
+
19
+ def self.package_managers
20
+ [
21
+ NPM,
22
+ Bower,
23
+ Packagist,
24
+ CPAN,
25
+ Meteor,
26
+ Cargo,
27
+ Pub,
28
+ Rubygems,
29
+ CocoaPods
30
+ ]
31
+ end
32
+
33
+ def self.ignored_files
34
+ ['.git'].join('|')
35
+ end
36
+ end
@@ -0,0 +1,33 @@
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
@@ -0,0 +1,56 @@
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
@@ -0,0 +1,3 @@
1
+ # Cartfile
2
+ # Cartfile.lock
3
+ # Cartfile.resolved
@@ -0,0 +1 @@
1
+ # project.clj
@@ -0,0 +1,78 @@
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
@@ -0,0 +1,57 @@
1
+ require 'yaml'
2
+ require 'json'
3
+
4
+ module Bibliothecary
5
+ class CPAN
6
+ def self.analyse(folder_path, file_list)
7
+ [analyse_json(folder_path, file_list),
8
+ analyse_yaml(folder_path, file_list)]
9
+ end
10
+
11
+ def self.analyse_json(folder_path, file_list)
12
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^META\.json$/i) }
13
+ return unless path
14
+
15
+ manifest = JSON.parse File.open(path).read
16
+
17
+ {
18
+ platform: 'cpan',
19
+ path: path,
20
+ dependencies: parse_json_manifest(manifest)
21
+ }
22
+ end
23
+
24
+ def self.analyse_yaml(folder_path, file_list)
25
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^META\.yml$/i) }
26
+ return unless path
27
+
28
+ manifest = YAML.load File.open(path).read
29
+
30
+ {
31
+ platform: 'cpan',
32
+ path: path,
33
+ dependencies: parse_yaml_manifest(manifest)
34
+ }
35
+ end
36
+
37
+ def self.parse_json_manifest(manifest)
38
+ manifest['prereqs'].map do |group, deps|
39
+ map_dependencies(deps, 'requires', 'runtime')
40
+ end.flatten
41
+ end
42
+
43
+ def self.parse_yaml_manifest(manifest)
44
+ map_dependencies(manifest, 'requires', 'runtime')
45
+ end
46
+
47
+ def self.map_dependencies(hash, key, type)
48
+ hash.fetch(key,[]).map do |name, requirement|
49
+ {
50
+ name: name,
51
+ requirement: requirement,
52
+ type: type
53
+ }
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,4 @@
1
+ # dub.json
2
+ # dub.sdl
3
+
4
+ # http://sdl4r.rubyforge.org/
@@ -0,0 +1,3 @@
1
+ # elm-package.json
2
+ # elm_dependencies.json
3
+ # elm-stuff/exact-dependencies.json
@@ -0,0 +1,2 @@
1
+ # glide.yaml
2
+ # glide.lock
@@ -0,0 +1,2 @@
1
+ # mix.exs
2
+ # mix.lock
@@ -0,0 +1 @@
1
+ # REQUIRE
@@ -0,0 +1,2 @@
1
+ # pom.xml
2
+ # ivy.xml
@@ -0,0 +1,32 @@
1
+ require 'json'
2
+
3
+ module Bibliothecary
4
+ class Meteor
5
+ def self.analyse(folder_path, file_list)
6
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^versions\.json$/) }
7
+ return unless path
8
+
9
+ manifest = JSON.parse File.open(path).read
10
+
11
+ {
12
+ platform: 'meteor',
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
+ end
21
+
22
+ def self.map_dependencies(hash, key, type)
23
+ hash.fetch(key,[]).map do |name, requirement|
24
+ {
25
+ name: name,
26
+ requirement: requirement,
27
+ type: type
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,61 @@
1
+ require 'json'
2
+
3
+ module Bibliothecary
4
+ class NPM
5
+ def self.analyse(folder_path, file_list)
6
+ [analyse_package_json(folder_path, file_list),
7
+ analyse_shrinkwrap(folder_path, file_list)]
8
+ end
9
+
10
+ def self.analyse_package_json(folder_path, file_list)
11
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^package\.json$/) }
12
+ return unless path
13
+
14
+ manifest = JSON.parse File.open(path).read
15
+
16
+ {
17
+ platform: 'npm',
18
+ path: path,
19
+ dependencies: parse_manifest(manifest)
20
+ }
21
+ end
22
+
23
+ def self.analyse_shrinkwrap(folder_path, file_list)
24
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^npm-shrinkwrap\.json$/) }
25
+ return unless path
26
+
27
+ manifest = JSON.parse File.open(path).read
28
+
29
+ {
30
+ platform: 'npm',
31
+ path: path,
32
+ dependencies: parse_shrinkwrap(manifest)
33
+ }
34
+ end
35
+
36
+ def self.parse_shrinkwrap(manifest)
37
+ manifest.fetch('dependencies',[]).map do |name, requirement|
38
+ {
39
+ name: name,
40
+ requirement: requirement["version"],
41
+ type: 'runtime'
42
+ }
43
+ end
44
+ end
45
+
46
+ def self.parse_manifest(manifest)
47
+ map_dependencies(manifest, 'dependencies', 'runtime') +
48
+ map_dependencies(manifest, 'devDependencies', 'development')
49
+ end
50
+
51
+ def self.map_dependencies(hash, key, type)
52
+ hash.fetch(key,[]).map do |name, requirement|
53
+ {
54
+ name: name,
55
+ requirement: requirement,
56
+ type: type
57
+ }
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,4 @@
1
+ # packages.config
2
+ # Project.json
3
+ # Project.lock.json
4
+ # *.nuspec
@@ -0,0 +1,61 @@
1
+ require 'json'
2
+
3
+ module Bibliothecary
4
+ class Packagist
5
+ def self.analyse(folder_path, file_list)
6
+ [analyse_composer_json(folder_path, file_list),
7
+ analyse_composer_lock(folder_path, file_list)]
8
+ end
9
+
10
+ def self.analyse_composer_json(folder_path, file_list)
11
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^composer\.json$/) }
12
+ return unless path
13
+
14
+ manifest = JSON.parse File.open(path).read
15
+
16
+ {
17
+ platform: 'Packagist',
18
+ path: path,
19
+ dependencies: parse_manifest(manifest)
20
+ }
21
+ end
22
+
23
+ def self.analyse_composer_lock(folder_path, file_list)
24
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^composer\.lock$/) }
25
+ return unless path
26
+
27
+ manifest = JSON.parse File.open(path).read
28
+
29
+ {
30
+ platform: 'Packagist',
31
+ path: path,
32
+ dependencies: parse_lockfile(manifest)
33
+ }
34
+ end
35
+
36
+ def self.parse_lockfile(manifest)
37
+ manifest.fetch('packages',[]).map do |dependency|
38
+ {
39
+ name: dependency["name"],
40
+ requirement: dependency["version"],
41
+ type: 'runtime'
42
+ }
43
+ end
44
+ end
45
+
46
+ def self.parse_manifest(manifest)
47
+ map_dependencies(manifest, 'require', 'runtime') +
48
+ map_dependencies(manifest, 'require-dev', 'development')
49
+ end
50
+
51
+ def self.map_dependencies(hash, key, type)
52
+ hash.fetch(key,[]).map do |name, requirement|
53
+ {
54
+ name: name,
55
+ requirement: requirement,
56
+ type: type
57
+ }
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,63 @@
1
+ require 'yaml'
2
+
3
+ module Bibliothecary
4
+ class Pub
5
+ def self.analyse(folder_path, file_list)
6
+ [
7
+ analyse_yaml(folder_path, file_list),
8
+ analyse_lockfile(folder_path, file_list)
9
+ ]
10
+ end
11
+
12
+ def self.analyse_yaml(folder_path, file_list)
13
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^pubspec\.yaml$/i) }
14
+ return unless path
15
+
16
+ manifest = YAML.load File.open(path).read
17
+
18
+ {
19
+ platform: 'Pub',
20
+ path: path,
21
+ dependencies: parse_yaml_manifest(manifest)
22
+ }
23
+ end
24
+
25
+ def self.analyse_lockfile(folder_path, file_list)
26
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^pubspec\.lock$/i) }
27
+ return unless path
28
+
29
+ manifest = YAML.load File.open(path).read
30
+
31
+ {
32
+ platform: 'Pub',
33
+ path: path,
34
+ dependencies: parse_yaml_manifest(manifest)
35
+ }
36
+ end
37
+
38
+ def self.parse_yaml_manifest(manifest)
39
+ map_dependencies(manifest, 'dependencies', 'runtime') +
40
+ map_dependencies(manifest, 'dev_dependencies', 'development')
41
+ end
42
+
43
+ def self.parse_yaml_lockfile(manifest)
44
+ manifest.fetch('packages', []).map do |name, dep|
45
+ {
46
+ name: name,
47
+ requirement: dep['version'],
48
+ type: type
49
+ }
50
+ end
51
+ end
52
+
53
+ def self.map_dependencies(hash, key, type)
54
+ hash.fetch(key,[]).map do |name, requirement|
55
+ {
56
+ name: name,
57
+ requirement: requirement,
58
+ type: type
59
+ }
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,5 @@
1
+ # setup.py
2
+ # req*.txt
3
+ # req*.pip
4
+ # requirements/*.txt
5
+ # requirements/*.pip
@@ -0,0 +1,79 @@
1
+ require 'gemnasium/parser'
2
+
3
+ module Bibliothecary
4
+ class Rubygems
5
+ NAME_VERSION = '(?! )(.*?)(?: \(([^-]*)(?:-(.*))?\))?'.freeze
6
+ NAME_VERSION_4 = /^ {4}#{NAME_VERSION}$/
7
+
8
+ def self.analyse(folder_path, file_list)
9
+ [
10
+ analyse_gemfile(folder_path, file_list),
11
+ analyse_gemspec(folder_path, file_list),
12
+ analyse_gemfile_lock(folder_path, file_list)
13
+ ]
14
+ end
15
+
16
+ def self.analyse_gemfile(folder_path, file_list)
17
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^Gemfile$|^gems\.rb$/) }
18
+ return unless path
19
+
20
+ manifest = Gemnasium::Parser.send(:gemfile, File.open(path).read)
21
+
22
+ {
23
+ platform: 'Rubygems',
24
+ path: path,
25
+ dependencies: parse_manifest(manifest)
26
+ }
27
+ end
28
+
29
+ def self.analyse_gemspec(folder_path, file_list)
30
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^[A-Za-z0-9_-]+\.gemspec$/) }
31
+ return unless path
32
+
33
+ manifest = Gemnasium::Parser.send(:gemspec, File.open(path).read)
34
+
35
+ {
36
+ platform: 'Rubygems',
37
+ path: path,
38
+ dependencies: parse_manifest(manifest)
39
+ }
40
+ end
41
+
42
+ def self.analyse_gemfile_lock(folder_path, file_list)
43
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^Gemfile\.lock$|^gems\.locked$/) }
44
+ return unless path
45
+
46
+ manifest = File.open(path).read
47
+
48
+ {
49
+ platform: 'Rubygems',
50
+ path: path,
51
+ dependencies: parse_gemfile_lock(manifest)
52
+ }
53
+ end
54
+
55
+ def self.parse_gemfile_lock(manifest)
56
+ manifest.split("\n").map do |line|
57
+ match = line.match(NAME_VERSION_4)
58
+ next unless match
59
+ name = match[1]
60
+ version = match[2].gsub(/\(|\)/,'')
61
+ {
62
+ name: name,
63
+ requirement: version,
64
+ type: 'runtime'
65
+ }
66
+ end.compact
67
+ end
68
+
69
+ def self.parse_manifest(manifest)
70
+ manifest.dependencies.inject([]) do |deps, dep|
71
+ deps.push({
72
+ name: dep.name,
73
+ requirement: dep.requirement.to_s,
74
+ type: dep.type
75
+ })
76
+ end.uniq
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,3 @@
1
+ module Bibliothecary
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bibliothecary
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Nesbitt
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: toml-rb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.9
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.9
27
+ - !ruby/object:Gem::Dependency
28
+ name: gemnasium-parser
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description:
84
+ email:
85
+ - andrewnez@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - README.md
96
+ - Rakefile
97
+ - bibliothecary.gemspec
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/bibliothecary.rb
101
+ - lib/bibliothecary/bower.rb
102
+ - lib/bibliothecary/cargo.rb
103
+ - lib/bibliothecary/carthage.rb
104
+ - lib/bibliothecary/clojars.rb
105
+ - lib/bibliothecary/cocoapods.rb
106
+ - lib/bibliothecary/cpan.rb
107
+ - lib/bibliothecary/dub.rb
108
+ - lib/bibliothecary/elm.rb
109
+ - lib/bibliothecary/go.rb
110
+ - lib/bibliothecary/hex.rb
111
+ - lib/bibliothecary/julia.rb
112
+ - lib/bibliothecary/maven.rb
113
+ - lib/bibliothecary/meteor.rb
114
+ - lib/bibliothecary/npm.rb
115
+ - lib/bibliothecary/nuget.rb
116
+ - lib/bibliothecary/packagist.rb
117
+ - lib/bibliothecary/pub.rb
118
+ - lib/bibliothecary/pypi.rb
119
+ - lib/bibliothecary/rubygems.rb
120
+ - lib/bibliothecary/version.rb
121
+ homepage: https://github.com/librariesio/bibliothecary
122
+ licenses: []
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.5.1
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Find and parse manifests
144
+ test_files: []