strong_versions 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/.strong_versions.yml +2 -0
- data/Makefile +5 -0
- data/README.md +1 -1
- data/bin/strong_versions +1 -2
- data/config/locales/en.yml +14 -5
- data/lib/strong_versions.rb +9 -17
- data/lib/strong_versions/config.rb +5 -5
- data/lib/strong_versions/dependencies.rb +26 -13
- data/lib/strong_versions/dependency.rb +35 -10
- data/lib/strong_versions/dependency_finder.rb +30 -0
- data/lib/strong_versions/suggestion.rb +53 -0
- data/lib/strong_versions/terminal.rb +80 -25
- data/lib/strong_versions/version.rb +1 -1
- data/strong_versions.gemspec +2 -0
- metadata +34 -6
- data/lib/strong_versions/gemfile_dsl.rb +0 -29
- data/lib/strong_versions/i18n_stub.rb +0 -9
- data/lib/strong_versions/install_detector.rb +0 -21
- data/plugins.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adffa925b8acf616a7d80b8f7122efcd450375d3dd001dbf7a7735a13199a415
|
4
|
+
data.tar.gz: 3495a49f991f76bff0f75ea9d726a324eac68819b821dd419a1a8f8ea5b8e641
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f88d7e3db8ad162490eb0426a48638fa8c5195d1b7ffc2342d8084166cd7af46fe5bd0667a2703ce68e3ef0fb54addc32739b0a1e8612f2dd5651d68d8848a5e
|
7
|
+
data.tar.gz: 9a798e3a31a229f9191daf7e631171c5cd757bbf1d01db4426b905caa7b6ac6f4bfa76f3234fba778a96f131e11bd43fdb58fae4d20a7f1047cc14fef462c9b1
|
data/.rubocop.yml
CHANGED
data/Makefile
ADDED
data/README.md
CHANGED
data/bin/strong_versions
CHANGED
@@ -4,8 +4,7 @@ require 'strong_versions'
|
|
4
4
|
|
5
5
|
config_path = Bundler.root.join('.strong_versions.yml')
|
6
6
|
config = StrongVersions::Config.new(config_path)
|
7
|
-
dependencies =
|
8
|
-
|
7
|
+
dependencies = StrongVersions::DependencyFinder.new.dependencies
|
9
8
|
valid = StrongVersions::Dependencies.new(dependencies).validate!(
|
10
9
|
except: config.exceptions,
|
11
10
|
on_failure: 'warn'
|
data/config/locales/en.yml
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
en:
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
strong_versions:
|
3
|
+
checked: "gem definitions inspected"
|
4
|
+
no_issues: 'no issues'
|
5
|
+
issue: 'issue'
|
6
|
+
issues: 'issues'
|
7
|
+
detected: 'detected'
|
8
|
+
|
9
|
+
errors:
|
10
|
+
failure: "StrongVersions Failure"
|
11
|
+
operator: "Expected pessimistic operator:"
|
12
|
+
version: "Expected major and minor version or unstable version, e.g."
|
13
|
+
unknown_on_failure: "StrongVersions: Unknown value for `on_failure` in .strong_versions.yml: '%{on_failure}'. Expected one of %{expected}"
|
14
|
+
suggested: 'Suggested: '
|
15
|
+
version_not_specified: "[not specified]"
|
data/lib/strong_versions.rb
CHANGED
@@ -2,32 +2,24 @@
|
|
2
2
|
|
3
3
|
require 'yaml'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
I18n.config.available_locales = :en
|
8
|
-
I18n.load_path += Dir[
|
9
|
-
File.join(
|
10
|
-
File.expand_path('..', __dir__), 'config', 'locales', '**', '*.yml'
|
11
|
-
)
|
12
|
-
]
|
13
|
-
rescue LoadError
|
14
|
-
require 'strong_versions/i18n_stub'
|
15
|
-
end
|
5
|
+
require 'i18n'
|
6
|
+
require 'paint'
|
16
7
|
|
17
8
|
require 'strong_versions/config'
|
18
9
|
require 'strong_versions/dependency'
|
10
|
+
require 'strong_versions/dependency_finder'
|
19
11
|
require 'strong_versions/dependencies'
|
20
|
-
require 'strong_versions/
|
21
|
-
require 'strong_versions/install_detector'
|
12
|
+
require 'strong_versions/suggestion'
|
22
13
|
require 'strong_versions/terminal'
|
23
14
|
require 'strong_versions/version'
|
24
15
|
|
25
16
|
module StrongVersions
|
26
|
-
def self.installed?
|
27
|
-
InstallDetector.new.installed?
|
28
|
-
end
|
29
|
-
|
30
17
|
def self.root
|
31
18
|
Pathname.new(File.dirname(__dir__))
|
32
19
|
end
|
33
20
|
end
|
21
|
+
|
22
|
+
I18n.config.available_locales = :en
|
23
|
+
I18n.load_path += Dir[
|
24
|
+
StrongVersions.root.join('config', 'locales', '**', '*.yml')
|
25
|
+
]
|
@@ -3,19 +3,19 @@
|
|
3
3
|
module StrongVersions
|
4
4
|
class Config
|
5
5
|
def initialize(path)
|
6
|
-
@config =
|
6
|
+
@config = YAML.load_file(path) if File.exist?(path)
|
7
7
|
|
8
8
|
validate_on_failure
|
9
9
|
end
|
10
10
|
|
11
11
|
def exceptions
|
12
|
-
return []
|
12
|
+
return [] unless @config
|
13
13
|
|
14
14
|
@config.fetch('ignore', [])
|
15
15
|
end
|
16
16
|
|
17
17
|
def on_failure
|
18
|
-
return 'raise'
|
18
|
+
return 'raise' unless @config
|
19
19
|
|
20
20
|
@config.fetch('on_failure', 'raise')
|
21
21
|
end
|
@@ -29,8 +29,8 @@ module StrongVersions
|
|
29
29
|
|
30
30
|
raise Bundler::BundlerError,
|
31
31
|
I18n.t(
|
32
|
-
'errors.unknown_on_failure',
|
33
|
-
|
32
|
+
'strong_versions.errors.unknown_on_failure',
|
33
|
+
on_failure: strategy, expected: expected
|
34
34
|
)
|
35
35
|
end
|
36
36
|
end
|
@@ -7,19 +7,17 @@ module StrongVersions
|
|
7
7
|
Dependency.new(raw_dependency)
|
8
8
|
end
|
9
9
|
@invalid_gems = []
|
10
|
+
@terminal = Terminal.new
|
10
11
|
end
|
11
12
|
|
12
13
|
def validate!(options = {})
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
case on_failure
|
17
|
-
when 'raise'
|
18
|
-
raise_failure
|
19
|
-
when 'warn'
|
20
|
-
warn_failure
|
14
|
+
if validate(options)
|
15
|
+
summary
|
16
|
+
return true
|
21
17
|
end
|
22
18
|
|
19
|
+
raise_or_warn(options.fetch(:on_failure, 'raise'))
|
20
|
+
summary
|
23
21
|
false
|
24
22
|
end
|
25
23
|
|
@@ -35,6 +33,19 @@ module StrongVersions
|
|
35
33
|
|
36
34
|
private
|
37
35
|
|
36
|
+
def summary
|
37
|
+
@terminal.summary(@dependencies.size, @invalid_gems.size)
|
38
|
+
end
|
39
|
+
|
40
|
+
def raise_or_warn(on_failure)
|
41
|
+
case on_failure
|
42
|
+
when 'raise'
|
43
|
+
raise_failure
|
44
|
+
when 'warn'
|
45
|
+
warn_failure
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
38
49
|
def raise_failure
|
39
50
|
warn_failure
|
40
51
|
# We must raise an error that Bundler recognises otherwise it prints a
|
@@ -44,17 +55,19 @@ module StrongVersions
|
|
44
55
|
end
|
45
56
|
|
46
57
|
def warn_failure
|
47
|
-
terminal
|
48
|
-
terminal.warn("\nStrongVersions expectations not met:\n")
|
58
|
+
@terminal.warn("\n#{I18n.t('strong_versions.errors.failure')}\n")
|
49
59
|
@invalid_gems.each do |gem|
|
50
|
-
terminal.output_errors(gem
|
60
|
+
@terminal.output_errors(gem)
|
51
61
|
end
|
52
|
-
terminal.puts("\n")
|
62
|
+
@terminal.puts("\n")
|
53
63
|
end
|
54
64
|
|
55
65
|
def raise_unknown(on_failure)
|
56
66
|
raise Bundler::Error,
|
57
|
-
I18n.t(
|
67
|
+
I18n.t(
|
68
|
+
'strong_versions.errors.unknown_on_failure',
|
69
|
+
on_failure: on_failure
|
70
|
+
)
|
58
71
|
end
|
59
72
|
end
|
60
73
|
end
|
@@ -4,10 +4,11 @@ module StrongVersions
|
|
4
4
|
class Dependency
|
5
5
|
attr_reader :name, :errors
|
6
6
|
|
7
|
-
def initialize(dependency)
|
7
|
+
def initialize(dependency, lockfile = nil)
|
8
8
|
@dependency = dependency
|
9
9
|
@name = dependency.name
|
10
10
|
@errors = []
|
11
|
+
@lockfile = lockfile || default_lockfile
|
11
12
|
|
12
13
|
versions.each do |operator, version|
|
13
14
|
validate_version(operator, version)
|
@@ -18,6 +19,14 @@ module StrongVersions
|
|
18
19
|
@errors.empty?
|
19
20
|
end
|
20
21
|
|
22
|
+
def suggestion
|
23
|
+
Suggestion.new(lockfile_version)
|
24
|
+
end
|
25
|
+
|
26
|
+
def definition
|
27
|
+
versions.map { |operator, version| "'#{operator} #{version}'" }.join(', ')
|
28
|
+
end
|
29
|
+
|
21
30
|
private
|
22
31
|
|
23
32
|
def versions
|
@@ -28,13 +37,25 @@ module StrongVersions
|
|
28
37
|
|
29
38
|
def parse_version(requirement)
|
30
39
|
operator, version_obj = Gem::Requirement.parse(requirement)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
40
|
+
[operator, version(version_obj)]
|
41
|
+
end
|
42
|
+
|
43
|
+
def lockfile_version
|
44
|
+
@lockfile_version ||= version(
|
45
|
+
@lockfile.specs.find { |spec| spec.name == @name }&.version
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def default_lockfile
|
50
|
+
Bundler::LockfileParser.new(Bundler.read_file(Bundler.default_lockfile))
|
51
|
+
end
|
52
|
+
|
53
|
+
def version(version_obj)
|
54
|
+
# Ruby >= 2.3.0: `version_obj` is a `Gem::Version`
|
55
|
+
return version_obj.version if version_obj.respond_to?(:version)
|
56
|
+
|
57
|
+
# Ruby < 2.3.0: `version_obj` is a `String`
|
58
|
+
version_obj
|
38
59
|
end
|
39
60
|
|
40
61
|
def validate_version(operator, version)
|
@@ -54,8 +75,12 @@ module StrongVersions
|
|
54
75
|
def check_valid_version(version)
|
55
76
|
return if valid_version?(version)
|
56
77
|
|
57
|
-
|
58
|
-
|
78
|
+
value = if version == '0'
|
79
|
+
I18n.t('strong_versions.version_not_specified')
|
80
|
+
else
|
81
|
+
version
|
82
|
+
end
|
83
|
+
@errors << { type: :version, value: value }
|
59
84
|
end
|
60
85
|
|
61
86
|
def pessimistic?(operator)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module StrongVersions
|
4
|
+
class DependencyFinder
|
5
|
+
def dependencies
|
6
|
+
development + runtime
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def development
|
12
|
+
# Gem runtime dependencies are not included here:
|
13
|
+
Bundler.definition.dependencies
|
14
|
+
end
|
15
|
+
|
16
|
+
def runtime
|
17
|
+
gemspecs.compact.map(&:dependencies).flatten.select do |spec|
|
18
|
+
spec.type == :runtime
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def gemspecs
|
23
|
+
gemspec_paths.map { |path| Bundler.load_gemspec(path) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def gemspec_paths
|
27
|
+
Dir[File.join(Bundler.default_gemfile.dirname, '{,*}.gemspec')]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module StrongVersions
|
4
|
+
class Suggestion
|
5
|
+
def initialize(version)
|
6
|
+
@parts = version.split('.') unless version.nil?
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_s
|
10
|
+
return version.to_s if version.nil?
|
11
|
+
|
12
|
+
"'~> #{version}'"
|
13
|
+
end
|
14
|
+
|
15
|
+
def missing?
|
16
|
+
return false if stable?
|
17
|
+
return false if unstable?
|
18
|
+
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def version
|
25
|
+
major, minor, patch = @parts if standard?
|
26
|
+
|
27
|
+
return "#{major}.#{minor}" if stable?
|
28
|
+
return "#{major}.#{minor}.#{patch}" if unstable?
|
29
|
+
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def unstable?
|
34
|
+
standard? && @parts.first.to_i.zero?
|
35
|
+
end
|
36
|
+
|
37
|
+
def stable?
|
38
|
+
standard? && @parts.first.to_i >= 1
|
39
|
+
end
|
40
|
+
|
41
|
+
def standard?
|
42
|
+
return false if @parts.nil?
|
43
|
+
return false unless @parts.size == 3
|
44
|
+
return false unless numeric?
|
45
|
+
|
46
|
+
true
|
47
|
+
end
|
48
|
+
|
49
|
+
def numeric?
|
50
|
+
@parts.all? { |part| part =~ /\A[0-9]+\Z/ }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -2,50 +2,105 @@
|
|
2
2
|
|
3
3
|
module StrongVersions
|
4
4
|
class Terminal
|
5
|
-
COLOR_CODES = {
|
6
|
-
red: 31,
|
7
|
-
green: 32,
|
8
|
-
light_red: 91
|
9
|
-
}.freeze
|
10
|
-
|
11
5
|
def initialize(file = STDERR)
|
12
6
|
@file = file
|
13
|
-
check_i18n
|
14
7
|
end
|
15
8
|
|
16
9
|
def warn(string)
|
17
|
-
puts(color(:
|
10
|
+
puts(color(string, :underline, :bright, :red))
|
18
11
|
end
|
19
12
|
|
20
|
-
def
|
21
|
-
puts(
|
13
|
+
def summary(count, failed)
|
14
|
+
return puts(success(count)) if failed.zero?
|
15
|
+
|
16
|
+
puts(failure(count, failed))
|
22
17
|
end
|
23
18
|
|
24
|
-
def
|
19
|
+
def output_errors(gem)
|
20
|
+
puts(name_and_definition(gem))
|
21
|
+
|
22
|
+
puts(format_errors(gem.errors))
|
23
|
+
suggestion(gem)
|
24
|
+
puts
|
25
|
+
end
|
26
|
+
|
27
|
+
def puts(string = '')
|
25
28
|
@file.puts(string)
|
26
29
|
end
|
27
30
|
|
28
31
|
private
|
29
32
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
def t(name)
|
34
|
+
I18n.t("strong_versions.#{name}")
|
35
|
+
end
|
36
|
+
|
37
|
+
# Success and failure output format brazenly stolen from Rubocop.
|
38
|
+
def success(count)
|
39
|
+
color(
|
40
|
+
"#{count} #{t('checked')}, %{no_issues} #{t('detected')}",
|
41
|
+
:default,
|
42
|
+
no_issues: [t('no_issues'), :green]
|
43
|
+
)
|
37
44
|
end
|
38
45
|
|
39
|
-
def
|
40
|
-
|
41
|
-
|
46
|
+
def failure(count, failed)
|
47
|
+
issues = "#{failed} " + (failed == 1 ? t('issue') : t('issues'))
|
48
|
+
color(
|
49
|
+
"#{count} #{t('checked')}, %{issues} #{t('detected')}",
|
50
|
+
:default,
|
51
|
+
issues: [issues, :red]
|
52
|
+
)
|
42
53
|
end
|
43
54
|
|
44
|
-
def
|
45
|
-
|
55
|
+
def format_errors(errors)
|
56
|
+
errors.map do |error|
|
57
|
+
type = t("errors.#{error[:type]}")
|
58
|
+
color(
|
59
|
+
' %{type} %{example}, found: %{found}',
|
60
|
+
:default,
|
61
|
+
type: [type, :default],
|
62
|
+
example: example(error[:type]),
|
63
|
+
found: [error[:value], :red]
|
64
|
+
)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def suggestion(gem)
|
69
|
+
suggested = ' ' + t('errors.suggested')
|
70
|
+
puts(
|
71
|
+
color(
|
72
|
+
"#{suggested} %{suggestion}",
|
73
|
+
:default,
|
74
|
+
suggestion: [gem.suggestion.to_s, :green]
|
75
|
+
)
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
def name_and_definition(gem)
|
80
|
+
color(
|
81
|
+
'`%{name}`: %{definition}',
|
82
|
+
:default,
|
83
|
+
name: [gem.name, :reset, :bright, :red],
|
84
|
+
definition: [gem.definition, :reset, :red]
|
85
|
+
)
|
86
|
+
end
|
87
|
+
|
88
|
+
def example(type)
|
89
|
+
case type
|
90
|
+
when :operator
|
91
|
+
color('~>', :green)
|
92
|
+
when :version
|
93
|
+
color('%{major} or %{minor}', :default, major: ['1.2', :green],
|
94
|
+
minor: ['0.2.3', :green])
|
95
|
+
else
|
96
|
+
raise ArgumentError
|
97
|
+
end
|
98
|
+
end
|
46
99
|
|
47
|
-
|
48
|
-
|
100
|
+
def color(string, *substitutions)
|
101
|
+
# rubocop:disable Style/FormatString, Layout/SpaceAroundOperators
|
102
|
+
Paint%[string.dup, *substitutions]
|
103
|
+
# rubocop:enable Style/FormatString, Layout/SpaceAroundOperators
|
49
104
|
end
|
50
105
|
end
|
51
106
|
end
|
data/strong_versions.gemspec
CHANGED
@@ -29,7 +29,9 @@ Gem::Specification.new do |spec|
|
|
29
29
|
# I will do a release that is locked to '~> 1.0' and Rails 4 users can use
|
30
30
|
# an older version of the gem but we are not quite there yet.
|
31
31
|
spec.add_dependency 'i18n', '>= 0.5.0'
|
32
|
+
spec.add_dependency 'paint', '~> 2.0'
|
32
33
|
|
34
|
+
spec.add_development_dependency 'betterp', '~> 0.1.2'
|
33
35
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
34
36
|
spec.add_development_dependency 'byebug', '~> 10.0'
|
35
37
|
spec.add_development_dependency 'rake', '~> 10.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strong_versions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Farrell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.5.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: paint
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: betterp
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.1.2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.1.2
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: bundler
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,9 +148,11 @@ files:
|
|
120
148
|
- ".rspec"
|
121
149
|
- ".rubocop.yml"
|
122
150
|
- ".ruby-version"
|
151
|
+
- ".strong_versions.yml"
|
123
152
|
- ".travis.yml"
|
124
153
|
- Gemfile
|
125
154
|
- LICENSE
|
155
|
+
- Makefile
|
126
156
|
- README.md
|
127
157
|
- Rakefile
|
128
158
|
- bin/console
|
@@ -137,12 +167,10 @@ files:
|
|
137
167
|
- lib/strong_versions/config.rb
|
138
168
|
- lib/strong_versions/dependencies.rb
|
139
169
|
- lib/strong_versions/dependency.rb
|
140
|
-
- lib/strong_versions/
|
141
|
-
- lib/strong_versions/
|
142
|
-
- lib/strong_versions/install_detector.rb
|
170
|
+
- lib/strong_versions/dependency_finder.rb
|
171
|
+
- lib/strong_versions/suggestion.rb
|
143
172
|
- lib/strong_versions/terminal.rb
|
144
173
|
- lib/strong_versions/version.rb
|
145
|
-
- plugins.rb
|
146
174
|
- strong_versions.gemspec
|
147
175
|
homepage: https://github.com/bobf/strong_versions
|
148
176
|
licenses: []
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module StrongVersions
|
4
|
-
class GemfileDSL
|
5
|
-
attr_reader :_strong_versions__installed
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
@_strong_versions__installed = false
|
9
|
-
end
|
10
|
-
|
11
|
-
def plugin(name, *_args)
|
12
|
-
@_strong_versions__installed = true if name == 'strong_versions'
|
13
|
-
end
|
14
|
-
|
15
|
-
# If we don't explicitly define this method then RubyGems' Kernel#gem is
|
16
|
-
# called instead.
|
17
|
-
def gem(*_args); end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
# rubocop:disable Style/MethodMissingSuper
|
22
|
-
def method_missing(_method, *_args, &_block); end
|
23
|
-
# rubocop:enable Style/MethodMissingSuper
|
24
|
-
|
25
|
-
def respond_to_missing?(_method)
|
26
|
-
true
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module StrongVersions
|
4
|
-
class InstallDetector
|
5
|
-
def initialize(gemfiles = nil)
|
6
|
-
@gemfiles = gemfiles.nil? ? Bundler.definition.gemfiles : gemfiles
|
7
|
-
@dsl = GemfileDSL.new
|
8
|
-
end
|
9
|
-
|
10
|
-
def installed?
|
11
|
-
@gemfiles.each do |gemfile|
|
12
|
-
# Bundler uses the same strategy to parse Gemfiles.
|
13
|
-
@dsl.instance_eval(
|
14
|
-
Bundler.read_file(gemfile).dup.untaint, gemfile.to_s, 1
|
15
|
-
)
|
16
|
-
end
|
17
|
-
|
18
|
-
@dsl._strong_versions__installed
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/plugins.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# XXX: StrongVersions was intended to be a Bundler plugin but, unfortunately,
|
4
|
-
# the plugin system is still in its infancy and has many issues which make it
|
5
|
-
# not fit for purpose. If those issues get resolved then I will re-add
|
6
|
-
# documentation for use as a plugin.
|
7
|
-
|
8
|
-
require 'strong_versions'
|
9
|
-
|
10
|
-
Bundler::Plugin.add_hook('before-install-all') do |dependencies|
|
11
|
-
# `StrongVersions.installed?` checks to see if 'strong_versions' is a
|
12
|
-
# dependency (i.e. included in the `Gemfile`). The reason for this is that,
|
13
|
-
# once a plugin has been installed, removing it from the `Gemfile` does not
|
14
|
-
# remove the plugin or its hooks so the hook will still run on every
|
15
|
-
# `bundle install`. I think that is not what a user would expect so we check
|
16
|
-
# that the plugin is explicitly referenced in the `Gemfile`.
|
17
|
-
run_hook(dependencies) if StrongVersions.installed?
|
18
|
-
end
|
19
|
-
|
20
|
-
def run_hook(dependencies)
|
21
|
-
config_path = Bundler.root.join('.strong_versions.yml')
|
22
|
-
config = StrongVersions::Config.new(config_path)
|
23
|
-
|
24
|
-
StrongVersions::Dependencies.new(dependencies).validate!(
|
25
|
-
except: config.exceptions,
|
26
|
-
on_failure: config.on_failure
|
27
|
-
)
|
28
|
-
end
|