eac_ruby_gems_utils 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '0830253271f8c28f89bd1bbc8a05ffc93fa026386ea791e8447c59694a6de8a7'
4
+ data.tar.gz: a26a28cad0b5807a4ff25b8339e3f71a579d598dc1c2b0fd562035bd47ec3aaa
5
+ SHA512:
6
+ metadata.gz: 58e8acf493436867fc6f5aad058308c4622d78bd774c6a2ec920d794390ea63bc064930b9cae7e586652d16d6c1d16c3b28acec248d1ffcd0c5a8ec08bdf31db
7
+ data.tar.gz: 5e22feaa46ae1e2119490975e1a59dac53e9879e32183aef5d028d983e16f5ddd55640eb516e1549d886e3e80c616f44a2c492af5c704c073cb5cdaa751061b0
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = E.A.C.'s Ruby Gems Utils.
2
+
3
+ Utilities for Ruby\'s gems development.
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/envs'
5
+
6
+ module EacRubyGemsUtils
7
+ class Gem
8
+ enable_simple_cache
9
+
10
+ common_constructor :root
11
+ set_callback :initialize, :after do
12
+ @root = ::Pathname.new(root).expand_path
13
+ end
14
+
15
+ def to_s
16
+ root.basename.to_s
17
+ end
18
+
19
+ def bundle(*args)
20
+ ::EacRubyUtils::Envs.local.command('bundle', *args)
21
+ .envvar('BUNDLE_GEMFILE', gemfile_path)
22
+ .chdir(root)
23
+ end
24
+
25
+ def gemfile_lock_gem_version(gem_name)
26
+ gemfile_lock_content.specs.find { |gem| gem.name == gem_name }.if_present(&:version)
27
+ end
28
+
29
+ def gemfile_lock_content
30
+ ::Bundler::LockfileParser.new(::Bundler.read_file(gemfile_lock_path))
31
+ end
32
+
33
+ private
34
+
35
+ def gemfile_path_uncached
36
+ root.join('Gemfile')
37
+ end
38
+
39
+ def gemfile_lock_path_uncached
40
+ root.join('Gemfile.lock')
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/fs_cache'
5
+ require 'eac_ruby_utils/listable'
6
+ require 'eac_ruby_utils/on_clean_ruby_environment'
7
+
8
+ module EacRubyUtils
9
+ module Tests
10
+ class Base
11
+ include ::EacRubyUtils::Listable
12
+
13
+ enable_simple_cache
14
+ lists.add_string :result, :failed, :nonexistent, :successful
15
+
16
+ common_constructor :gem
17
+
18
+ def elegible?
19
+ dependency_present? && gem.root.join(test_directory).exist?
20
+ end
21
+
22
+ def dependency_present?
23
+ gem.gemfile_path.exist? && gem.gemfile_lock_gem_version(dependency_gem).present?
24
+ end
25
+
26
+ def name
27
+ self.class.name.demodulize.gsub(/Test\z/, '')
28
+ end
29
+
30
+ def stdout_cache
31
+ root_cache.child('stdout')
32
+ end
33
+
34
+ def stderr_cache
35
+ root_cache.child('stderr')
36
+ end
37
+
38
+ def to_s
39
+ "#{gem}[#{name}]"
40
+ end
41
+
42
+ private
43
+
44
+ def result_uncached
45
+ return RESULT_NONEXISTENT unless elegible?
46
+ bundle_run ? RESULT_SUCCESSFUL : RESULT_FAILED
47
+ end
48
+
49
+ def bundle_run
50
+ r = ::EacRubyUtils.on_clean_ruby_environment do
51
+ gem.bundle('exec', *bundle_exec_args).execute
52
+ end
53
+ stdout_cache.write(r[:stdout])
54
+ stderr_cache.write(r[:stderr])
55
+ r[:exit_code].zero?
56
+ end
57
+
58
+ def root_cache
59
+ ::EacRubyUtils.fs_cache.child(gem.root.to_s.parameterize, self.class.name.parameterize)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_gems_utils/tests/base'
4
+
5
+ module EacRubyGemsUtils
6
+ module Tests
7
+ class Minitest < ::EacRubyGemsUtils::Minitest
8
+ def bundle_exec_args
9
+ %w[rake test]
10
+ end
11
+
12
+ def dependency_gem
13
+ 'minitest'
14
+ end
15
+
16
+ def test_directory
17
+ 'test'
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_gems_utils/tests/base'
4
+
5
+ module EacRubyGemsUtils
6
+ module Tests
7
+ class Rspec < ::EacRubyUtils::Gem::Test
8
+ def bundle_exec_args
9
+ %w[rspec]
10
+ end
11
+
12
+ def dependency_gem
13
+ 'rspec-core'
14
+ end
15
+
16
+ def test_directory
17
+ 'spec'
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module EacRubyGemsUtils
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'eac_ruby_utils/core_ext'
2
+
3
+ module EacRubyGemsUtils
4
+ require_sub(__FILE__)
5
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eac_ruby_gems_utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Esquilo Azul Company
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-02-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: eac_ruby_utils
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.19'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.19'
27
+ description:
28
+ email:
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - README.rdoc
34
+ - lib/eac_ruby_gems_utils.rb
35
+ - lib/eac_ruby_gems_utils/gem.rb
36
+ - lib/eac_ruby_gems_utils/tests/base.rb
37
+ - lib/eac_ruby_gems_utils/tests/minitest.rb
38
+ - lib/eac_ruby_gems_utils/tests/rspec.rb
39
+ - lib/eac_ruby_gems_utils/version.rb
40
+ homepage:
41
+ licenses:
42
+ - GPL3
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.7.7
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Utilities for Ruby gems development.
64
+ test_files: []