eac_ruby_gems_utils 0.6.2 → 0.8.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b640e8bf4f8118ad8bc047b79bb4929331324a132b79edf6f62a1f14bf524181
4
- data.tar.gz: dcbae45900e3e2ab4f6060c1a7e9df16326069cc4a0fc7f26bd05f3399636755
3
+ metadata.gz: f53674fe550c42bfff29451c72ce82b786a519967088b7294378b0b74159e283
4
+ data.tar.gz: ca4835aac1a8d8e404b3b77fbb0a86c5a7ed239686e41d17ca39e0cb86189f35
5
5
  SHA512:
6
- metadata.gz: 00e3f662232c805327e4468e776cef5d9dad1b7f71fb4ad39bfd9f0451a6f4aca8ae69b2a42390940ad6927550dc22b86f038e5b8831ef012fef955ae5a6f5f3
7
- data.tar.gz: 79e8483d80458612ec4f82154fd469f209d231ad4c83e55ad9f553de98917926598c13f54b878651dd19d0a33afd1ad4401456a165f724ea8f2d87624ad1d4b6
6
+ metadata.gz: 855c6e6831bc15ad059764124c1133e43079f54810e1e66343834fc9075fbedc6a79325ff844a53bd4cc08807c4da5e48413be2952ebc7739e29e73f8b1d9931
7
+ data.tar.gz: 5f5d51cf0b8dde23ad1aeebee3a67847e66d135bc5e03e0ccfd2d99ef383bc5ae8964bcf33f65ccbc2e9f53511a0043e9de05cc74bfc5ff4ed59fe3653c3b72f
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
4
  require 'eac_ruby_utils/envs'
5
+ require 'rubygems'
5
6
 
6
7
  module EacRubyGemsUtils
7
8
  class Gem
@@ -10,8 +11,9 @@ module EacRubyGemsUtils
10
11
 
11
12
  GEMSPEC_EXTNAME = '.gemspec'
12
13
 
13
- common_constructor :root do
14
+ common_constructor :root, :host_env, default: [nil] do
14
15
  @root = ::Pathname.new(root).expand_path
16
+ self.host_env ||= ::EacRubyUtils::Envs.local
15
17
  end
16
18
 
17
19
  def to_s
@@ -22,6 +24,11 @@ module EacRubyGemsUtils
22
24
  ::EacRubyGemsUtils::Gem::Command.new(self, %w[bundle] + args).envvar_gemfile
23
25
  end
24
26
 
27
+ # @return A [Pathname] array with relative paths from root listed in gemspec's .file directive.
28
+ def files
29
+ gemspec.files.map(&:to_pathname)
30
+ end
31
+
25
32
  def gemfile_lock_gem_version(gem_name)
26
33
  gemfile_lock_content.specs.find { |gem| gem.name == gem_name }.if_present(&:version)
27
34
  end
@@ -54,7 +61,7 @@ module EacRubyGemsUtils
54
61
  end
55
62
 
56
63
  def version
57
- /VERSION\s*=\s*[\'\"]([^\'\"]+)[\'\"]/.if_match(version_file.read) { |m| m[1] }
64
+ version_file.value
58
65
  end
59
66
 
60
67
  private
@@ -67,6 +74,10 @@ module EacRubyGemsUtils
67
74
  gemfile_path.basename_sub { |b| "#{b}.lock" }
68
75
  end
69
76
 
77
+ def gemspec_uncached
78
+ ::Gem::Specification.load(gemspec_path.to_path)
79
+ end
80
+
70
81
  def gemspec_path_uncached
71
82
  ::Pathname.glob("#{root.to_path}/*#{GEMSPEC_EXTNAME}").first
72
83
  end
@@ -76,6 +87,10 @@ module EacRubyGemsUtils
76
87
  end
77
88
 
78
89
  def version_file_uncached
90
+ ::EacRubyGemsUtils::Gem::VersionFile.new(version_file_path)
91
+ end
92
+
93
+ def version_file_path_uncached
79
94
  root.join('lib', *namespace_parts, 'version.rb')
80
95
  end
81
96
  end
@@ -11,7 +11,7 @@ module EacRubyGemsUtils
11
11
 
12
12
  def initialize(gem, command_args, extra_options = {})
13
13
  @gem = gem
14
- super(command_args, extra_options)
14
+ super(command_args, extra_options.merge(host_env: gem.host_env))
15
15
  end
16
16
 
17
17
  # Changes current directory to the gem's directory.
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacRubyGemsUtils
6
+ class Gem
7
+ class VersionFile
8
+ common_constructor :path
9
+
10
+ VERSION_LINE_PATTERN = /\A(\s*)VERSION\s*=\s*[\'\"]([^\'\"]+)[\'\"](\s*)\z/.freeze
11
+
12
+ def value
13
+ path.read.each_line.lazy.map { |line| line_value(line) }.find { |v| v }
14
+ end
15
+
16
+ def value=(new_value)
17
+ path.write(new_value_content(new_value))
18
+ end
19
+
20
+ private
21
+
22
+ # @return Version found in line, nil otherwise.
23
+ def line_value(line)
24
+ VERSION_LINE_PATTERN.if_match(line.rstrip, false) { |m| ::Gem::Version.new(m[2]) }
25
+ end
26
+
27
+ def new_value_content(new_value)
28
+ path.read.each_line
29
+ .map { |line| new_value_line(line, new_value) }
30
+ .join
31
+ end
32
+
33
+ def new_value_line(line, new_value)
34
+ m = VERSION_LINE_PATTERN.match(line)
35
+ return line unless m
36
+
37
+ "#{m[1]}VERSION = '#{new_value}'#{m[3]}"
38
+ end
39
+ end
40
+ end
41
+ end
@@ -7,6 +7,7 @@ require 'eac_ruby_utils/core_ext'
7
7
  module EacRubyGemsUtils
8
8
  module Tests
9
9
  class Multiple
10
+ require_sub __FILE__
10
11
  enable_console_speaker
11
12
  enable_simple_cache
12
13
  common_constructor :gems, :options, default: [{}]
@@ -26,14 +27,9 @@ module EacRubyGemsUtils
26
27
  decorated_gems.flat_map(&:tests)
27
28
  end
28
29
 
29
- def bundle_all_gems
30
- infom 'Bundling all gems...'
31
- decorated_gems.each do |gem|
32
- next unless gem.gemfile_path.exist?
33
-
34
- infov 'Bundle install', gem
35
- gem.bundle.execute!
36
- end
30
+ def prepare_all_gems
31
+ infom 'Preparing all gems...'
32
+ decorated_gems.each(&:prepare)
37
33
  end
38
34
 
39
35
  def decorated_gems_uncached
@@ -61,7 +57,7 @@ module EacRubyGemsUtils
61
57
 
62
58
  def run
63
59
  start_banner
64
- bundle_all_gems
60
+ prepare_all_gems
65
61
  test_all_gems
66
62
  final_results_banner
67
63
  end
@@ -76,31 +72,6 @@ module EacRubyGemsUtils
76
72
  infov test, Result.new(test.result).tag
77
73
  end
78
74
  end
79
-
80
- class DecoratedGem < ::SimpleDelegator
81
- def tests
82
- [::EacRubyGemsUtils::Tests::Minitest.new(__getobj__),
83
- ::EacRubyGemsUtils::Tests::Rspec.new(__getobj__)]
84
- end
85
- end
86
-
87
- class Result
88
- common_constructor :result
89
-
90
- COLORS = {
91
- ::EacRubyGemsUtils::Tests::Base::RESULT_FAILED => :red,
92
- ::EacRubyGemsUtils::Tests::Base::RESULT_NONEXISTENT => :white,
93
- ::EacRubyGemsUtils::Tests::Base::RESULT_SUCCESSFUL => :green
94
- }.freeze
95
-
96
- def tag
97
- result.to_s.send(color)
98
- end
99
-
100
- def color
101
- COLORS.fetch(result)
102
- end
103
- end
104
75
  end
105
76
  end
106
77
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyGemsUtils
4
+ module Tests
5
+ class Multiple
6
+ class DecoratedGem < ::SimpleDelegator
7
+ enable_console_speaker
8
+
9
+ def prepare
10
+ return unless gemfile_path.exist?
11
+
12
+ log('running "bundle install"...')
13
+ return if bundle('install').execute.fetch(:exit_code).zero?
14
+
15
+ unless can_remove_gemfile_lock?
16
+ raise '"bundle install" failed and the Gemfile.lock is part of gem' \
17
+ '(Should be changed by developer)'
18
+ end
19
+
20
+ prepare_with_removable_gemfile_lock
21
+ end
22
+
23
+ def tests
24
+ [::EacRubyGemsUtils::Tests::Minitest.new(__getobj__),
25
+ ::EacRubyGemsUtils::Tests::Rspec.new(__getobj__)]
26
+ end
27
+
28
+ private
29
+
30
+ def log(message)
31
+ infov self, message
32
+ end
33
+
34
+ def prepare_with_removable_gemfile_lock
35
+ log('"bundle install" failed, removing Gemfile.lock and trying again...')
36
+ gemfile_lock_path.unlink if gemfile_lock_path.exist?
37
+ bundle('install').execute!
38
+ end
39
+
40
+ def can_remove_gemfile_lock?
41
+ !files.include?(gemfile_lock_path.relative_path_from(root))
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyGemsUtils
4
+ module Tests
5
+ class Multiple
6
+ class Result
7
+ common_constructor :result
8
+
9
+ COLORS = {
10
+ ::EacRubyGemsUtils::Tests::Base::RESULT_FAILED => :red,
11
+ ::EacRubyGemsUtils::Tests::Base::RESULT_NONEXISTENT => :white,
12
+ ::EacRubyGemsUtils::Tests::Base::RESULT_SUCCESSFUL => :green
13
+ }.freeze
14
+
15
+ def tag
16
+ result.to_s.send(color)
17
+ end
18
+
19
+ def color
20
+ COLORS.fetch(result)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyGemsUtils
4
- VERSION = '0.6.2'
4
+ VERSION = '0.8.0'
5
5
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_gems_utils/gem'
4
+
5
+ ::RSpec.describe ::EacRubyGemsUtils::Gem::VersionFile do
6
+ let(:stubs_dir) { ::Pathname.new(__dir__).join('version_file_spec_files') }
7
+ let(:stub_file) { stubs_dir.join('a_version_file.rb') }
8
+ let(:instance) { described_class.new(stub_file) }
9
+ let(:target_version) { ::Gem::Version.new('0.69.1') }
10
+
11
+ describe '#value' do
12
+ it { expect(instance.value).to eq(target_version) }
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Tools
5
+ VERSION = '0.69.1'
6
+ end
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_ruby_gems_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-14 00:00:00.000000000 Z
11
+ date: 2020-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_ruby_utils
@@ -55,14 +55,19 @@ files:
55
55
  - lib/eac_ruby_gems_utils.rb
56
56
  - lib/eac_ruby_gems_utils/gem.rb
57
57
  - lib/eac_ruby_gems_utils/gem/command.rb
58
+ - lib/eac_ruby_gems_utils/gem/version_file.rb
58
59
  - lib/eac_ruby_gems_utils/tests.rb
59
60
  - lib/eac_ruby_gems_utils/tests/base.rb
60
61
  - lib/eac_ruby_gems_utils/tests/minitest.rb
61
62
  - lib/eac_ruby_gems_utils/tests/multiple.rb
63
+ - lib/eac_ruby_gems_utils/tests/multiple/decorated_gem.rb
64
+ - lib/eac_ruby_gems_utils/tests/multiple/result.rb
62
65
  - lib/eac_ruby_gems_utils/tests/rspec.rb
63
66
  - lib/eac_ruby_gems_utils/version.rb
67
+ - spec/code/rubocop_check_spec.rb
68
+ - spec/lib/eac_ruby_gems_utils/gem/version_file_spec.rb
69
+ - spec/lib/eac_ruby_gems_utils/gem/version_file_spec_files/a_version_file.rb
64
70
  - spec/lib/eac_ruby_gems_utils/gem_spec.rb
65
- - spec/rubocop_check_spec.rb
66
71
  - spec/spec_helper.rb
67
72
  - spec/support/mygem/Gemfile
68
73
  - spec/support/mygem/Gemfile.lock
@@ -97,8 +102,10 @@ signing_key:
97
102
  specification_version: 4
98
103
  summary: Utilities for Ruby gems development.
99
104
  test_files:
105
+ - spec/code/rubocop_check_spec.rb
106
+ - spec/lib/eac_ruby_gems_utils/gem/version_file_spec.rb
107
+ - spec/lib/eac_ruby_gems_utils/gem/version_file_spec_files/a_version_file.rb
100
108
  - spec/lib/eac_ruby_gems_utils/gem_spec.rb
101
- - spec/rubocop_check_spec.rb
102
109
  - spec/spec_helper.rb
103
110
  - spec/support/mygem/Gemfile
104
111
  - spec/support/mygem/Gemfile.lock