eac_ruby_gems_utils 0.3.0 → 0.6.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: fa382fd75e266237e5358229ee3abbf7b1e31e3f953fb9e59b845cecb06fe937
4
- data.tar.gz: b58fcd6430e03ea9d3b219da5e44aa91ddbf19934982742ad92628028d7efa91
3
+ metadata.gz: 96ad40e228b3d95ed5f966a19d7449e860e1c6eddf0646492f7fc164bfaaf9b4
4
+ data.tar.gz: fa1d30195f503bf880d8dc9bb4f0063a550abd08bdef2d7c54e471c9039c87b2
5
5
  SHA512:
6
- metadata.gz: e45adccca691763dd270580a783839a9b5405eb401183e5ed4dd37609e14782b034d70595c46ee48dfd03b31d57166b7fe602c25c021055dc5a046db93ad5041
7
- data.tar.gz: cdd227d5aa78010e0dc95f7ec2560af92ff0c0a0a84e5edc2a34ecba87033874356de8a7e56ed1c4b1c99e69b8af23a57468a1c89957f687d19ccbea98b09707
6
+ metadata.gz: 117390a61ccaf50fcc9853a2926726d7196151b56626b3482d595d8278f4e06e4073c47e73733553f5e5acb3ddf169bb9f152715e8c13761ba8e9a0d124176ab
7
+ data.tar.gz: b6a2673cd0d582eadf7ca565dbe59b5015ae960a548debf313c80a3522d346b8ff9ad1bcc001e9e74a66e03742ff1abeb1fa6c938f71c8b6951a96ade387ae88
@@ -5,20 +5,21 @@ require 'eac_ruby_utils/envs'
5
5
 
6
6
  module EacRubyGemsUtils
7
7
  class Gem
8
+ require_sub __FILE__
8
9
  enable_simple_cache
9
10
 
10
- common_constructor :root
11
- set_callback :initialize, :after do
11
+ GEMSPEC_EXTNAME = '.gemspec'
12
+
13
+ common_constructor :root do
12
14
  @root = ::Pathname.new(root).expand_path
13
15
  end
14
16
 
15
17
  def to_s
16
- root.basename.to_s
18
+ name
17
19
  end
18
20
 
19
21
  def bundle(*args)
20
- ::EacRubyUtils::Envs.local.command('bundle', *args)
21
- .envvar('BUNDLE_GEMFILE', gemfile_path)
22
+ ::EacRubyGemsUtils::Gem::Command.new(self, %w[bundle] + args).envvar_gemfile
22
23
  end
23
24
 
24
25
  def gemfile_lock_gem_version(gem_name)
@@ -29,12 +30,32 @@ module EacRubyGemsUtils
29
30
  ::Bundler::LockfileParser.new(::Bundler.read_file(gemfile_lock_path))
30
31
  end
31
32
 
33
+ def name
34
+ name_by_gemspec || name_by_path
35
+ end
36
+
37
+ def name_by_gemspec
38
+ gemspec_path.if_present { |v| v.basename(GEMSPEC_EXTNAME).to_path }
39
+ end
40
+
41
+ def name_by_path
42
+ root.basename.to_s
43
+ end
44
+
45
+ def namespace_parts
46
+ name.split('-')
47
+ end
48
+
32
49
  def rake(*args)
33
50
  raise "File \"#{rakefile_path}\" does not exist" unless rakefile_path.exist?
34
51
 
35
52
  bundle('exec', 'rake', '--rakefile', rakefile_path, *args)
36
53
  end
37
54
 
55
+ def version
56
+ /VERSION\s*=\s*[\'\"]([^\'\"]+)[\'\"]/.if_match(version_file.read) { |m| m[1] }
57
+ end
58
+
38
59
  private
39
60
 
40
61
  def gemfile_path_uncached
@@ -45,8 +66,16 @@ module EacRubyGemsUtils
45
66
  root.join('Gemfile.lock')
46
67
  end
47
68
 
69
+ def gemspec_path_uncached
70
+ ::Pathname.glob("#{root.to_path}/*#{GEMSPEC_EXTNAME}").first
71
+ end
72
+
48
73
  def rakefile_path_uncached
49
74
  root.join('Rakefile')
50
75
  end
76
+
77
+ def version_file_uncached
78
+ root.join('lib', *namespace_parts, 'version.rb')
79
+ end
51
80
  end
52
81
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/ruby/command'
5
+ require 'delegate'
6
+
7
+ module EacRubyGemsUtils
8
+ class Gem
9
+ class Command < ::EacRubyUtils::Ruby::Command
10
+ attr_reader :gem
11
+
12
+ def initialize(gem, command_args, extra_options = {})
13
+ @gem = gem
14
+ super(command_args, extra_options)
15
+ end
16
+
17
+ # Changes current directory to the gem's directory.
18
+ def chdir_root
19
+ chdir(gem.root.to_path)
20
+ end
21
+
22
+ def envvar_gemfile
23
+ envvar('BUNDLE_GEMFILE', gem.gemfile_path.to_path)
24
+ end
25
+
26
+ protected
27
+
28
+ def duplicate(command, extra_options)
29
+ self.class.new(gem, command, extra_options)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -44,13 +44,15 @@ module EacRubyGemsUtils
44
44
  def result_uncached
45
45
  return RESULT_NONEXISTENT unless elegible?
46
46
 
47
- exec_run ? RESULT_SUCCESSFUL : RESULT_FAILED
47
+ exec_run_with_log ? RESULT_SUCCESSFUL : RESULT_FAILED
48
48
  end
49
49
 
50
50
  def exec_run
51
- r = ::EacRubyUtils.on_clean_ruby_environment do
52
- gem.send(exec_method, *exec_args).execute
53
- end
51
+ gem.bundle('exec', *bundle_exec_args).chdir_root.execute
52
+ end
53
+
54
+ def exec_run_with_log
55
+ r = exec_run
54
56
  stdout_cache.write(r[:stdout])
55
57
  stderr_cache.write(r[:stderr])
56
58
  r[:exit_code].zero?
@@ -5,12 +5,8 @@ require 'eac_ruby_gems_utils/tests/base'
5
5
  module EacRubyGemsUtils
6
6
  module Tests
7
7
  class Minitest < ::EacRubyGemsUtils::Tests::Base
8
- def exec_args
9
- %w[test]
10
- end
11
-
12
- def exec_method
13
- :rake
8
+ def bundle_exec_args
9
+ %w[rake test]
14
10
  end
15
11
 
16
12
  def dependency_gem
@@ -9,13 +9,17 @@ module EacRubyGemsUtils
9
9
  class Multiple
10
10
  enable_console_speaker
11
11
  enable_simple_cache
12
- common_constructor :gems
12
+ common_constructor :gems, :options, default: [{}]
13
13
  set_callback :initialize, :after, :run
14
14
 
15
15
  def ok?
16
16
  failed_tests.none?
17
17
  end
18
18
 
19
+ def only
20
+ options[:only]
21
+ end
22
+
19
23
  private
20
24
 
21
25
  def all_tests_uncached
@@ -33,7 +37,9 @@ module EacRubyGemsUtils
33
37
  end
34
38
 
35
39
  def decorated_gems_uncached
36
- gems.map { |gem| DecoratedGem.new(gem) }
40
+ r = gems
41
+ r = r.select { |gem| only.include?(gem.name) } if only.present?
42
+ r.map { |gem| DecoratedGem.new(gem) }
37
43
  end
38
44
 
39
45
  def failed_tests_uncached
@@ -5,12 +5,8 @@ require 'eac_ruby_gems_utils/tests/base'
5
5
  module EacRubyGemsUtils
6
6
  module Tests
7
7
  class Rspec < ::EacRubyGemsUtils::Tests::Base
8
- def exec_args
9
- %w[exec rspec]
10
- end
11
-
12
- def exec_method
13
- :bundle
8
+ def bundle_exec_args
9
+ %w[rspec]
14
10
  end
15
11
 
16
12
  def dependency_gem
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyGemsUtils
4
- VERSION = '0.3.0'
4
+ VERSION = '0.6.0'
5
5
  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.3.0
4
+ version: 0.6.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-04-11 00:00:00.000000000 Z
11
+ date: 2020-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_ruby_utils
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.20'
19
+ version: '0.29'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.20'
26
+ version: '0.29'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: eac_ruby_gem_support
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -47,6 +47,7 @@ files:
47
47
  - README.rdoc
48
48
  - lib/eac_ruby_gems_utils.rb
49
49
  - lib/eac_ruby_gems_utils/gem.rb
50
+ - lib/eac_ruby_gems_utils/gem/command.rb
50
51
  - lib/eac_ruby_gems_utils/tests.rb
51
52
  - lib/eac_ruby_gems_utils/tests/base.rb
52
53
  - lib/eac_ruby_gems_utils/tests/minitest.rb