avm 0.21.0 → 0.24.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3439e5be72641bfbb2057567b3066ee5a9fa0bb230ac4b755e541a501b2f51af
4
- data.tar.gz: 47d2db526602f0054663417bf5e3d519408df59ba1e03c0fb16c9dc5ef23871e
3
+ metadata.gz: 937c532ad108fabe2301a9e6a32048f0f0d8afd771d384d7079650c09a96f9c4
4
+ data.tar.gz: f76e3a10f12fa40c99bc1374039133f544e7d8757e771b581b27f5e85029c46e
5
5
  SHA512:
6
- metadata.gz: f50e41ecf763e2901de01276d03dffb24c4b1322ab28cca1c7d19a0860bddeef3433b42667209b480481c24e074bcbe05fb1148f13f6206427db1be33c160ca7
7
- data.tar.gz: 6d93ed47691853ae5a56c0577de8606ab72126fe4a83eefbf9d68ca6a88f1c6960369e8a183671fefdeb235b3a23550bbe5271d2d03382c7030de549948b0619
6
+ metadata.gz: 3c9e645ab258c0a24d70cde2b6ba74e0af37f1fd3d8c1390e60416862b9d6cb47b8c109776243da88447204a0bb13c90ab9ea3c27aa7dddd93cb9814aa0829ee
7
+ data.tar.gz: 8bf8b0fe97dd546a96af5abb7124d7740b66f1ce585613589281bee8aadb81075e7a0c8a305ae81e2dc7e50c2aa31ed1a3401cae7804664dfe592929fbb357b2
@@ -11,8 +11,7 @@ module Avm
11
11
 
12
12
  def detect(*registered_initialize_args)
13
13
  detect_optional(*registered_initialize_args) ||
14
- raise("No registered module valid for #{registered_initialize_args}" \
15
- " (Module suffix: #{module_suffix}, Available: #{registered_modules.join(', ')})")
14
+ raise_not_found(*registered_initialize_args)
16
15
  end
17
16
 
18
17
  def detect_optional(*registered_initialize_args)
@@ -38,6 +37,11 @@ module Avm
38
37
 
39
38
  private
40
39
 
40
+ def raise_not_found(*args)
41
+ raise("No registered module valid for #{args}" \
42
+ " (Module suffix: #{module_suffix}, Available: #{registered_modules.join(', ')})")
43
+ end
44
+
41
45
  def registered_modules_uncached
42
46
  registered_gems.flat_map { |registry| modules_from_registry(registry) }
43
47
  .select { |v| valid_registered_module?(v) }.uniq
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/registry/base'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Registry
8
+ class WithPath < ::Avm::Registry::Base
9
+ def detect_by_path(path)
10
+ detect_by_path_optional(path) || raise_not_found(path)
11
+ end
12
+
13
+ def detect_by_path_optional(path)
14
+ current_path = path.to_pathname.expand_path
15
+ until current_path.root?
16
+ detect_optional(current_path).if_present { |v| return v }
17
+ current_path = current_path.parent
18
+ end
19
+ nil
20
+ end
21
+ end
22
+ end
23
+ end
data/lib/avm/registry.rb CHANGED
@@ -9,6 +9,8 @@ module Avm
9
9
  enable_listable
10
10
  lists.add_symbol :category, :instance_stereotypes, :runners, :scms, :sources
11
11
 
12
+ WITH_PATH = [CATEGORY_SCMS, CATEGORY_SOURCES].freeze
13
+
12
14
  class << self
13
15
  enable_simple_cache
14
16
 
@@ -21,7 +23,15 @@ module Avm
21
23
 
22
24
  ::Avm::Registry.lists.category.each_value do |category|
23
25
  define_method "#{category}_uncached" do
24
- ::Avm::Registry::Base.new(category.to_s.camelize)
26
+ registry_class(category).new(category.to_s.camelize)
27
+ end
28
+ end
29
+
30
+ def registry_class(category)
31
+ if WITH_PATH.include?(category)
32
+ ::Avm::Registry::WithPath
33
+ else
34
+ ::Avm::Registry::Base
25
35
  end
26
36
  end
27
37
  end
data/lib/avm/scms/base.rb CHANGED
@@ -33,13 +33,8 @@ module Avm
33
33
  private
34
34
 
35
35
  # @return [Avm::Scms::Base]
36
- def parent_scm
37
- parent_path = path.parent
38
- until parent_path.root?
39
- ::Avm::Registry.scms.detect_optional(parent_path).if_present { |v| return v }
40
- parent_path = parent_path.parent
41
- end
42
- nil
36
+ def parent_scm_uncached
37
+ ::Avm::Registry.scms.detect_by_path_optional(path.parent)
43
38
  end
44
39
  end
45
40
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/scms/base'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Scms
8
+ class Null < ::Avm::Scms::Base
9
+ def update
10
+ # Do nothing
11
+ end
12
+ end
13
+ end
14
+ end
@@ -9,21 +9,39 @@ module Avm
9
9
  module Sources
10
10
  class Base
11
11
  module Configuration
12
+ CONFIGURATION_FILENAMES = %w[.avm.yml .avm.yaml].freeze
13
+
14
+ # @return [EacRubyUtils::Envs::Command, nil]
15
+ def configuration_value_to_env_command(value)
16
+ configuration_value_to_shell_words(value).if_present { |v| env.command(v).chdir(path) }
17
+ end
18
+
19
+ # @return [Array<String>, nil]
20
+ def configuration_value_to_shell_words(value)
21
+ return nil if value.blank?
22
+
23
+ value.is_a?(::Enumerable) ? value.map(&:to_s) : ::Shellwords.split(value.to_s)
24
+ end
25
+
12
26
  # @return [Array<String>, nil]
13
27
  def read_configuration_as_shell_words(key)
14
- configuration.entry(key).value.if_present do |v|
15
- v.is_a?(::Enumerable) ? v.map(&:to_s) : ::Shellwords.split(v.to_s)
16
- end
28
+ configuration_value_to_shell_words(configuration.entry(key).value)
29
+ end
30
+
31
+ # Utility to read a configuration as a [EacRubyUtils::Envs::Command].
32
+ # @return [EacRubyUtils::Envs::Command]
33
+ def read_configuration_as_env_command(key)
34
+ configuration_value_to_env_command(configuration.entry(key).value)
17
35
  end
18
36
 
19
37
  private
20
38
 
21
39
  # @return [EacConfig::YamlFileNode]
22
40
  def configuration_uncached
23
- ::Avm::Sources::Configuration::FILENAMES.each do |filename|
41
+ CONFIGURATION_FILENAMES.each do |filename|
24
42
  configuration_with_filename(filename, true)
25
43
  end
26
- configuration_with_filename(::Avm::Sources::Configuration::FILENAMES.first, false)
44
+ configuration_with_filename(CONFIGURATION_FILENAMES.first, false)
27
45
  end
28
46
 
29
47
  # @return [EacConfig::YamlFileNode, nil]
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'i18n'
5
+
6
+ module Avm
7
+ module Sources
8
+ class Base
9
+ module Locale
10
+ LOCALE_KEY = 'locale'
11
+
12
+ def locale
13
+ configured_locale || default_locale
14
+ end
15
+
16
+ def configured_locale
17
+ configuration.entry(LOCALE_KEY).value
18
+ end
19
+
20
+ def default_locale
21
+ ::I18n.default_locale
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/sources/base/subs_paths'
4
+ require 'eac_cli/runner_with/subcommands'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module Avm
8
+ module Sources
9
+ class Base
10
+ module Runners
11
+ # @return [Hash<String, EacCli::Runner>]
12
+ def extra_available_subcommands
13
+ extra_available_subcommands_from_runners_module
14
+ end
15
+
16
+ # @return [Hash<String, EacCli::Runner>]
17
+ def extra_available_subcommands_from_runners_module
18
+ self.class.ancestors.reverse.inject({}) do |a, e|
19
+ a.merge(RunnersFromModule.new(e).result)
20
+ end
21
+ end
22
+
23
+ class RunnersFromModule
24
+ enable_simple_cache
25
+ common_constructor :the_module
26
+
27
+ # @return [Hash<String, EacCli::Runner>]
28
+ def result
29
+ return {} if runners_module.blank?
30
+
31
+ ::EacCli::RunnerWith::Subcommands.subcommands_from_module(runners_module)
32
+ end
33
+
34
+ def runners_module_uncached
35
+ return nil if the_module.module_parent.blank?
36
+
37
+ begin
38
+ the_module.module_parent.const_get('Runners')
39
+ rescue ::NameError
40
+ nil
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,19 +1,68 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/envs/command'
4
5
 
5
6
  module Avm
6
7
  module Sources
7
8
  class Base
8
9
  module Testing
9
- # @return [Avm::Sources::Tester]
10
- def tester
11
- tester_class.new(self)
10
+ DEFAULT_TEST_COMMANDS = {}.freeze
11
+ TEST_KEY = 'test'
12
+ TEST_COMMAND_KEY = "#{TEST_KEY}.command"
13
+ TEST_COMMANDS_KEY = "#{TEST_KEY}.commands"
14
+
15
+ def configured_test_command
16
+ read_configuration_as_env_command(TEST_COMMAND_KEY)
17
+ end
18
+
19
+ # @return [Hash<String, EacRubyUtils::Envs::Command>, nil]
20
+ def configured_test_commands
21
+ configured_value_as_test_commands(configuration.entry(TEST_COMMANDS_KEY).value)
22
+ end
23
+
24
+ # @return [Hash<String, EacRubyUtils::Envs::Command>, nil]
25
+ def configured_value_as_test_commands(value)
26
+ return nil if value.blank?
27
+
28
+ [::EacRubyUtils::Envs::Command, ::Hash, ::Enumerable].each do |type|
29
+ next unless value.is_a?(type)
30
+
31
+ return send(
32
+ "configured_#{type.name.demodulize.variableize}_value_as_test_commands",
33
+ value
34
+ )
35
+ end
36
+
37
+ raise "Value for test commands should be a Hash or a Enumerable (Actual: #{value})"
38
+ end
39
+
40
+ # @return [Hash<String, EacRubyUtils::Envs::Command>]
41
+ def default_test_commands
42
+ DEFAULT_TEST_COMMANDS
43
+ end
44
+
45
+ # @return [Enumerable<EacRubyUtils::Envs::Command>]
46
+ def test_commands
47
+ configured_test_commands ||
48
+ configured_value_as_test_commands(configured_test_command)
49
+ default_test_commands
50
+ end
51
+
52
+ protected
53
+
54
+ def configured_command_value_as_test_commands(value)
55
+ configured_enumerable_value_as_test_commands([value])
56
+ end
57
+
58
+ def configured_enumerable_value_as_test_commands(value)
59
+ configured_hash_value_as_test_commands(
60
+ value.each_with_index.map { |v| ["test_#{v[1]}", v[0]] }.to_h
61
+ )
12
62
  end
13
63
 
14
- # @return [Class<Avm::Sources::Tester>
15
- def tester_class
16
- Avm::Sources::Tester
64
+ def configured_hash_value_as_test_commands(value)
65
+ value.map { |k, v| [k.to_s.strip, configuration_value_to_env_command(v)] }.to_h
17
66
  end
18
67
  end
19
68
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'avm/registry'
4
+ require 'avm/scms/null'
4
5
  require 'eac_git'
5
6
  require 'eac_ruby_utils/core_ext'
6
7
 
@@ -20,18 +21,11 @@ module Avm
20
21
 
21
22
  abstract_methods :update, :valid?
22
23
 
23
- delegate :locale, to: :old_configuration
24
-
25
24
  # @return [EacRubyUtils::Envs::LocalEnv]
26
25
  def env
27
26
  ::EacRubyUtils::Envs::LocalEnv.new
28
27
  end
29
28
 
30
- # @return [Hash<String, Class>]
31
- def extra_available_subcommands
32
- {}
33
- end
34
-
35
29
  # @return [Pathname]
36
30
  def relative_path
37
31
  return path if parent.blank?
@@ -47,7 +41,7 @@ module Avm
47
41
 
48
42
  # @return [Avm::Scms::Base]
49
43
  def scm_uncached
50
- ::Avm::Registry.scms.detect(path)
44
+ ::Avm::Registry.scms.detect_optional(path) || ::Avm::Scms::Null.new(path)
51
45
  end
52
46
  end
53
47
  end
@@ -44,6 +44,13 @@ module Avm
44
44
  create_units(main_source.subs)
45
45
  end
46
46
 
47
+ # @return [Array<Avm::Sources::Tests::Single>]
48
+ def create_source_units(source)
49
+ source.test_commands.map do |test_name, test_command|
50
+ ::Avm::Sources::Tests::Single.new(self, source, test_name, test_command)
51
+ end
52
+ end
53
+
47
54
  # @return [Avm::Sources::Tests::Single]
48
55
  def create_unit(source)
49
56
  ::Avm::Sources::Tests::Single.new(self, source)
@@ -51,7 +58,7 @@ module Avm
51
58
 
52
59
  # @return [Array<Avm::Sources::Tests::Single>]
53
60
  def create_units(sources)
54
- sources.map { |a_source| create_unit(a_source) }
61
+ sources.flat_map { |a_source| create_source_units(a_source) }
55
62
  end
56
63
 
57
64
  # @return [Avm::Sources::Tests::Single]
@@ -14,9 +14,8 @@ module Avm
14
14
  enable_simple_cache
15
15
  enable_speaker
16
16
 
17
- common_constructor :builder, :source
17
+ common_constructor :builder, :source, :test_name, :test_command
18
18
 
19
- delegate :logs, :result, to: :tester
20
19
  delegate :to_s, to: :id
21
20
 
22
21
  def failed?
@@ -25,11 +24,7 @@ module Avm
25
24
 
26
25
  # @return [String]
27
26
  def id
28
- if main?
29
- MAIN_SOURCE_ID
30
- else
31
- relative_path_from_main_source.to_s
32
- end
27
+ "#{main? ? MAIN_SOURCE_ID : relative_path_from_main_source}\##{test_name}"
33
28
  end
34
29
 
35
30
  def main?
@@ -47,8 +42,32 @@ module Avm
47
42
 
48
43
  private
49
44
 
50
- def tester_uncached
51
- source.tester
45
+ # @return [EacFs::Logs]
46
+ def logs_uncached
47
+ ::EacFs::Logs.new.add(:stdout).add(:stderr)
48
+ end
49
+
50
+ # @return [Avm::Sources::Tests::Result]
51
+ def result_uncached
52
+ if test_command.blank?
53
+ ::Avm::Sources::Tests::Result::NONEXISTENT
54
+ elsif run_test_command
55
+ ::Avm::Sources::Tests::Result::SUCESSFUL
56
+ else
57
+ ::Avm::Sources::Tests::Result::FAILED
58
+ end
59
+ end
60
+
61
+ def run_test_command
62
+ execute_command_and_log(test_command)
63
+ end
64
+
65
+ # @return [true, false]
66
+ def execute_command_and_log(command)
67
+ r = command.execute
68
+ logs[:stdout].write(r[:stdout])
69
+ logs[:stderr].write(r[:stderr])
70
+ r[:exit_code].zero?
52
71
  end
53
72
  end
54
73
  end
data/lib/avm/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Avm
4
- VERSION = '0.21.0'
4
+ VERSION = '0.24.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.0
4
+ version: 0.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo H. Bogoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-29 00:00:00.000000000 Z
11
+ date: 2022-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_cli
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.23'
19
+ version: '0.27'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 0.23.1
22
+ version: 0.27.6
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '0.23'
29
+ version: '0.27'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 0.23.1
32
+ version: 0.27.6
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: eac_docker
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -226,6 +226,7 @@ files:
226
226
  - lib/avm/path_string.rb
227
227
  - lib/avm/registry.rb
228
228
  - lib/avm/registry/base.rb
229
+ - lib/avm/registry/with_path.rb
229
230
  - lib/avm/result.rb
230
231
  - lib/avm/rspec.rb
231
232
  - lib/avm/rspec/setup.rb
@@ -235,6 +236,7 @@ files:
235
236
  - lib/avm/scms/base.rb
236
237
  - lib/avm/scms/commit.rb
237
238
  - lib/avm/scms/inflector.rb
239
+ - lib/avm/scms/null.rb
238
240
  - lib/avm/self/docker_image.rb
239
241
  - lib/avm/self/instance.rb
240
242
  - lib/avm/self/instance/entry_keys.rb
@@ -242,15 +244,14 @@ files:
242
244
  - lib/avm/sources/base.rb
243
245
  - lib/avm/sources/base/configuration.rb
244
246
  - lib/avm/sources/base/instance.rb
247
+ - lib/avm/sources/base/locale.rb
245
248
  - lib/avm/sources/base/parent.rb
249
+ - lib/avm/sources/base/runners.rb
246
250
  - lib/avm/sources/base/subs.rb
247
251
  - lib/avm/sources/base/subs_paths.rb
248
252
  - lib/avm/sources/base/testing.rb
249
253
  - lib/avm/sources/configuration.rb
250
- - lib/avm/sources/configuration/locale.rb
251
254
  - lib/avm/sources/configuration/rubocop.rb
252
- - lib/avm/sources/configuration/tests.rb
253
- - lib/avm/sources/tester.rb
254
255
  - lib/avm/sources/tests.rb
255
256
  - lib/avm/sources/tests/builder.rb
256
257
  - lib/avm/sources/tests/performer.rb
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/patches/eac_ruby_gems_utils/gem'
4
- require 'i18n'
5
-
6
- module Avm
7
- module Sources
8
- class Configuration < ::EacConfig::OldConfigs
9
- module Locale
10
- LOCALE_KEY = :locale
11
-
12
- def locale
13
- read_entry(LOCALE_KEY) || ::I18n.default_locale
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/patches/eac_ruby_gems_utils/gem'
4
-
5
- module Avm
6
- module Sources
7
- class Configuration < ::EacConfig::OldConfigs
8
- module Tests
9
- BUNDLE_TEST_COMMAND_KEY = 'test.bundle_command'
10
- TEST_COMMAND_KEY = 'test.command'
11
-
12
- def any_test_command
13
- bundle_test_command || test_command
14
- end
15
-
16
- def test_command
17
- read_command(TEST_COMMAND_KEY)
18
- end
19
-
20
- def bundle_test_command
21
- read_entry(BUNDLE_TEST_COMMAND_KEY).if_present do |v|
22
- args = v.is_a?(::Enumerable) ? v.map(&:to_s) : ::Shellwords.split(v)
23
- ::EacRubyGemsUtils::Gem.new(::File.dirname(storage_path)).bundle(*args).chdir_root
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
-
5
- module Avm
6
- module Sources
7
- class Tester
8
- enable_abstract_methods
9
- common_constructor :source
10
-
11
- abstract_methods :result, :logs
12
-
13
- # @return [EacFs::Logs]
14
- def logs
15
- raise_abstract_method __method__
16
- end
17
-
18
- # @return [Avm::Sources::Tests::Result]
19
- def result
20
- raise_abstract_method __method__
21
- end
22
- end
23
- end
24
- end