bibliothecary 4.0.4 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +25 -0
  3. data/.github/CONTRIBUTING.md +165 -0
  4. data/.github/ISSUE_TEMPLATE.md +18 -0
  5. data/.github/PULL_REQUEST_TEMPLATE.md +10 -0
  6. data/.rubocop.yml +1156 -0
  7. data/.travis.yml +4 -1
  8. data/Gemfile +5 -0
  9. data/README.md +7 -1
  10. data/bibliothecary.gemspec +1 -1
  11. data/lib/bibliothecary.rb +16 -2
  12. data/lib/bibliothecary/analyser.rb +28 -4
  13. data/lib/bibliothecary/parsers/bower.rb +7 -10
  14. data/lib/bibliothecary/parsers/cargo.rb +9 -31
  15. data/lib/bibliothecary/parsers/carthage.rb +13 -34
  16. data/lib/bibliothecary/parsers/clojars.rb +4 -7
  17. data/lib/bibliothecary/parsers/cocoapods.rb +19 -30
  18. data/lib/bibliothecary/parsers/cpan.rb +10 -15
  19. data/lib/bibliothecary/parsers/cran.rb +7 -10
  20. data/lib/bibliothecary/parsers/dub.rb +7 -12
  21. data/lib/bibliothecary/parsers/elm.rb +7 -47
  22. data/lib/bibliothecary/parsers/go.rb +47 -52
  23. data/lib/bibliothecary/parsers/hex.rb +5 -14
  24. data/lib/bibliothecary/parsers/julia.rb +4 -7
  25. data/lib/bibliothecary/parsers/maven.rb +12 -18
  26. data/lib/bibliothecary/parsers/meteor.rb +6 -9
  27. data/lib/bibliothecary/parsers/npm.rb +15 -14
  28. data/lib/bibliothecary/parsers/nuget.rb +18 -28
  29. data/lib/bibliothecary/parsers/packagist.rb +9 -14
  30. data/lib/bibliothecary/parsers/pub.rb +9 -14
  31. data/lib/bibliothecary/parsers/pypi.rb +8 -10
  32. data/lib/bibliothecary/parsers/rubygems.rb +16 -23
  33. data/lib/bibliothecary/parsers/shard.rb +9 -14
  34. data/lib/bibliothecary/parsers/swift_pm.rb +4 -7
  35. data/lib/bibliothecary/version.rb +1 -1
  36. data/lib/sdl_parser.rb +0 -4
  37. metadata +9 -5
  38. data/CONTRIBUTING.md +0 -10
@@ -5,21 +5,15 @@ module Bibliothecary
5
5
  class Packagist
6
6
  include Bibliothecary::Analyser
7
7
 
8
- def self.parse(filename, path)
9
- if filename.match(/^composer\.json$/)
10
- file_contents = File.open(path).read
11
- json = JSON.parse(file_contents)
12
- parse_manifest(json)
13
- elsif filename.match(/^composer\.lock$/)
14
- file_contents = File.open(path).read
15
- json = JSON.parse(file_contents)
16
- parse_lockfile(json)
17
- else
18
- []
19
- end
8
+ def self.mapping
9
+ {
10
+ /^composer\.json$/ => :parse_manifest,
11
+ /^composer\.lock$/ => :parse_lockfile
12
+ }
20
13
  end
21
14
 
22
- def self.parse_lockfile(manifest)
15
+ def self.parse_lockfile(file_contents)
16
+ manifest = JSON.parse file_contents
23
17
  manifest.fetch('packages',[]).map do |dependency|
24
18
  {
25
19
  name: dependency["name"],
@@ -29,7 +23,8 @@ module Bibliothecary
29
23
  end
30
24
  end
31
25
 
32
- def self.parse_manifest(manifest)
26
+ def self.parse_manifest(file_contents)
27
+ manifest = JSON.parse file_contents
33
28
  map_dependencies(manifest, 'require', 'runtime') +
34
29
  map_dependencies(manifest, 'require-dev', 'development')
35
30
  end
@@ -5,26 +5,21 @@ module Bibliothecary
5
5
  class Pub
6
6
  include Bibliothecary::Analyser
7
7
 
8
- def self.parse(filename, path)
9
- if filename.match(/^pubspec\.yaml$/i)
10
- file_contents = File.open(path).read
11
- yaml = YAML.load file_contents
12
- parse_yaml_manifest(yaml)
13
- elsif filename.match(/^pubspec\.lock$/i)
14
- file_contents = File.open(path).read
15
- yaml = YAML.load file_contents
16
- parse_yaml_lockfile(yaml)
17
- else
18
- []
19
- end
8
+ def self.mapping
9
+ {
10
+ /^pubspec\.yaml$/i => :parse_yaml_manifest,
11
+ /^pubspec\.lock$/i => :parse_yaml_lockfile
12
+ }
20
13
  end
21
14
 
22
- def self.parse_yaml_manifest(manifest)
15
+ def self.parse_yaml_manifest(file_contents)
16
+ manifest = YAML.load file_contents
23
17
  map_dependencies(manifest, 'dependencies', 'runtime') +
24
18
  map_dependencies(manifest, 'dev_dependencies', 'development')
25
19
  end
26
20
 
27
- def self.parse_yaml_lockfile(manifest)
21
+ def self.parse_yaml_lockfile(file_contents)
22
+ manifest = YAML.load file_contents
28
23
  manifest.fetch('packages', []).map do |name, dep|
29
24
  {
30
25
  name: name,
@@ -7,19 +7,18 @@ module Bibliothecary
7
7
  REQUIRE_REGEXP = /([a-zA-Z0-9]+[a-zA-Z0-9\-_\.]+)([><=\d\.,]+)?/
8
8
  REQUIREMENTS_REGEXP = /^#{REQUIRE_REGEXP}/
9
9
 
10
- def self.parse(filename, path)
11
- is_valid_requirements_file = is_requirements_file(filename)
12
- if is_valid_requirements_file
13
- file_contents = File.open(path).read
14
- parse_requirements_txt(file_contents)
10
+ def self.parse_file(filename, contents)
11
+ if is_requirements_file(filename)
12
+ parse_requirements_txt(contents)
15
13
  elsif filename.match(/setup\.py$/)
16
- file_contents = File.open(path).read
17
- parse_setup_py(file_contents)
18
- else
19
- []
14
+ parse_setup_py(contents)
20
15
  end
21
16
  end
22
17
 
18
+ def self.match?(filename)
19
+ is_requirements_file(filename) || filename.match(/setup\.py$/)
20
+ end
21
+
23
22
  def self.parse_setup_py(manifest)
24
23
  match = manifest.match(INSTALL_REGEXP)
25
24
  return [] unless match
@@ -52,7 +51,6 @@ module Bibliothecary
52
51
  end
53
52
 
54
53
  def self.is_requirements_file(filename)
55
- is_requirements_file = filename.match(/require.*\.(txt|pip)$/)
56
54
  if filename.match(/require.*\.(txt|pip)$/) and !filename.match(/^node_modules/)
57
55
  return true
58
56
  else
@@ -8,21 +8,12 @@ module Bibliothecary
8
8
  NAME_VERSION = '(?! )(.*?)(?: \(([^-]*)(?:-(.*))?\))?'.freeze
9
9
  NAME_VERSION_4 = /^ {4}#{NAME_VERSION}$/
10
10
 
11
- def self.parse(filename, path)
12
- if filename.match(/^Gemfile$|^gems\.rb$/)
13
- file_contents = File.open(path).read
14
- manifest = Gemnasium::Parser.send(:gemfile, file_contents)
15
- parse_manifest(manifest)
16
- elsif filename.match(/[A-Za-z0-9_-]+\.gemspec$/)
17
- file_contents = File.open(path).read
18
- manifest = Gemnasium::Parser.send(:gemspec, file_contents)
19
- parse_manifest(manifest)
20
- elsif filename.match(/^Gemfile\.lock$|^gems\.locked$/)
21
- file_contents = File.open(path).read
22
- parse_gemfile_lock(file_contents)
23
- else
24
- []
25
- end
11
+ def self.mapping
12
+ {
13
+ /^Gemfile$|^gems\.rb$/ => :parse_gemfile,
14
+ /[A-Za-z0-9_-]+\.gemspec$/ => :parse_gemspec,
15
+ /^Gemfile\.lock$|^gems\.locked$/ => :parse_gemfile_lock
16
+ }
26
17
  end
27
18
 
28
19
  def self.parse_gemfile_lock(manifest)
@@ -39,15 +30,17 @@ module Bibliothecary
39
30
  end.compact
40
31
  end
41
32
 
42
- def self.parse_manifest(manifest)
43
- manifest.dependencies.inject([]) do |deps, dep|
44
- deps.push({
45
- name: dep.name,
46
- requirement: dep.requirement.to_s,
47
- type: dep.type
48
- })
49
- end.uniq
33
+ def self.parse_gemfile(file_contents)
34
+ manifest = Gemnasium::Parser.send(:gemfile, file_contents)
35
+ parse_ruby_manifest(manifest)
50
36
  end
37
+
38
+ def self.parse_gemspec(file_contents)
39
+ manifest = Gemnasium::Parser.send(:gemspec, file_contents)
40
+ parse_ruby_manifest(manifest)
41
+ end
42
+
43
+
51
44
  end
52
45
  end
53
46
  end
@@ -5,25 +5,20 @@ module Bibliothecary
5
5
  class Shard
6
6
  include Bibliothecary::Analyser
7
7
 
8
- def self.parse(filename, path)
9
- if filename.match(/^shard\.yml$/i)
10
- file_contents = File.open(path).read
11
- yaml = YAML.load file_contents
12
- parse_yaml_manifest(yaml)
13
- elsif filename.match(/^shard\.lock$/i)
14
- file_contents = File.open(path).read
15
- yaml = YAML.load file_contents
16
- parse_yaml_lockfile(yaml)
17
- else
18
- []
19
- end
8
+ def self.mapping
9
+ {
10
+ /^shard\.yml$/i => :parse_yaml_manifest,
11
+ /^shard\.lock$/i => :parse_yaml_lockfile
12
+ }
20
13
  end
21
14
 
22
- def self.parse_yaml_lockfile(manifest)
15
+ def self.parse_yaml_lockfile(file_contents)
16
+ manifest = YAML.load file_contents
23
17
  map_dependencies(manifest, 'shards', 'runtime')
24
18
  end
25
19
 
26
- def self.parse_yaml_manifest(manifest)
20
+ def self.parse_yaml_manifest(file_contents)
21
+ manifest = YAML.load file_contents
27
22
  map_dependencies(manifest, 'dependencies', 'runtime') +
28
23
  map_dependencies(manifest, 'development_dependencies', 'runtime')
29
24
  end
@@ -3,13 +3,10 @@ module Bibliothecary
3
3
  class SwiftPM
4
4
  include Bibliothecary::Analyser
5
5
 
6
- def self.parse(filename, path)
7
- if filename.match(/^Package\.swift$/i)
8
- file_contents = File.open(path).read
9
- parse_package_swift(file_contents)
10
- else
11
- []
12
- end
6
+ def self.mapping
7
+ {
8
+ /^Package\.swift$/i => :parse_package_swift
9
+ }
13
10
  end
14
11
 
15
12
  def self.parse_package_swift(manifest)
@@ -1,3 +1,3 @@
1
1
  module Bibliothecary
2
- VERSION = "4.0.4"
2
+ VERSION = "5.0.0"
3
3
  end
data/lib/sdl_parser.rb CHANGED
@@ -7,10 +7,6 @@ class SdlParser
7
7
  @type = type || 'runtime'
8
8
  end
9
9
 
10
- def to_json
11
- Oj.dump(dependencies, mode: :compat) unless contents.nil?
12
- end
13
-
14
10
  def dependencies
15
11
  parse.children('dependency').inject([]) do |deps, dep|
16
12
  deps.push({
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: 4.0.4
4
+ version: 5.0.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-12-16 00:00:00.000000000 Z
11
+ date: 2017-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: toml-rb
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '11.0'
117
+ version: '12.0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '11.0'
124
+ version: '12.0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rspec
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -143,11 +143,15 @@ executables: []
143
143
  extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
+ - ".codeclimate.yml"
147
+ - ".github/CONTRIBUTING.md"
148
+ - ".github/ISSUE_TEMPLATE.md"
149
+ - ".github/PULL_REQUEST_TEMPLATE.md"
146
150
  - ".gitignore"
147
151
  - ".rspec"
152
+ - ".rubocop.yml"
148
153
  - ".travis.yml"
149
154
  - CODE_OF_CONDUCT.md
150
- - CONTRIBUTING.md
151
155
  - Gemfile
152
156
  - LICENSE.txt
153
157
  - README.md
data/CONTRIBUTING.md DELETED
@@ -1,10 +0,0 @@
1
- # Contributing
2
-
3
- * Fork the project.
4
- * Make your feature addition or bug fix.
5
- * Add tests for it. This is important so I don't break it in a future version unintentionally.
6
- * Send a pull request. Bonus points for topic branches.
7
-
8
- ## Code of Conduct
9
-
10
- Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.