avm 0.24.0 → 0.27.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/application_stereotypes/base/by_gem.rb +17 -0
  3. data/lib/avm/application_stereotypes/base/detection.rb +34 -0
  4. data/lib/avm/application_stereotypes/base.rb +21 -0
  5. data/lib/avm/application_stereotypes.rb +9 -0
  6. data/lib/avm/{instances/application.rb → applications/base.rb} +5 -6
  7. data/lib/avm/applications.rb +9 -0
  8. data/lib/avm/instances/base.rb +7 -2
  9. data/lib/avm/instances.rb +1 -1
  10. data/lib/avm/registry/application_stereotypes/build_available.rb +46 -0
  11. data/lib/avm/registry/application_stereotypes/stereotype_builder.rb +30 -0
  12. data/lib/avm/registry/application_stereotypes.rb +36 -0
  13. data/lib/avm/registry/{base.rb → from_gems.rb} +13 -4
  14. data/lib/avm/registry/instances.rb +16 -0
  15. data/lib/avm/registry/runners.rb +10 -0
  16. data/lib/avm/registry/scms.rb +10 -0
  17. data/lib/avm/registry/sources.rb +10 -0
  18. data/lib/avm/registry/with_path/cache.rb +31 -0
  19. data/lib/avm/registry/with_path.rb +33 -7
  20. data/lib/avm/registry.rb +3 -7
  21. data/lib/avm/rspec/shared_examples/not_in_avm_registry.rb +1 -1
  22. data/lib/avm/sources/base/configuration.rb +23 -2
  23. data/lib/avm/sources/base/instance.rb +2 -2
  24. data/lib/avm/sources/base/locale.rb +1 -1
  25. data/lib/avm/sources/base/parent.rb +8 -11
  26. data/lib/avm/sources/base/subs_paths.rb +1 -1
  27. data/lib/avm/sources/base/testing.rb +4 -4
  28. data/lib/avm/sources/base.rb +4 -0
  29. data/lib/avm/sources/tests/builder.rb +17 -11
  30. data/lib/avm/version.rb +1 -1
  31. data/lib/avm/with_application_stereotype.rb +23 -0
  32. data/lib/avm/with_dynamic_runners.rb +42 -0
  33. metadata +33 -5
  34. data/lib/avm/sources/base/runners.rb +0 -47
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 937c532ad108fabe2301a9e6a32048f0f0d8afd771d384d7079650c09a96f9c4
4
- data.tar.gz: f76e3a10f12fa40c99bc1374039133f544e7d8757e771b581b27f5e85029c46e
3
+ metadata.gz: 6e8acabcae2be2a5ede0d16f23948a2fde0073eadcb0aa4affec5af992db9ee9
4
+ data.tar.gz: e2a626b43d125f5f3c79173753e8a94edf8d1894aca17ba5299a94a5e9f3639c
5
5
  SHA512:
6
- metadata.gz: 3c9e645ab258c0a24d70cde2b6ba74e0af37f1fd3d8c1390e60416862b9d6cb47b8c109776243da88447204a0bb13c90ab9ea3c27aa7dddd93cb9814aa0829ee
7
- data.tar.gz: 8bf8b0fe97dd546a96af5abb7124d7740b66f1ce585613589281bee8aadb81075e7a0c8a305ae81e2dc7e50c2aa31ed1a3401cae7804664dfe592929fbb357b2
6
+ metadata.gz: 758bf21073943b0e38cb7dccd36592220a6b55c4286e37be1b7fd33cb4476d3d4d72a3e4d097b64b2aad6a0790685ebf89460d51ecbe4bd60334051cd6a4af26
7
+ data.tar.gz: 827a1b04ef6b93dface81cf9d6e1c30f78d4b60fa3246a35147f124acbcc57839f7b26302b977fab10ddd9189894ab3536108d244c1920fa0f43c71fbbed8123
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module ApplicationStereotypes
5
+ class Base
6
+ module ByGem
7
+ common_concern
8
+
9
+ module ClassMethods
10
+ def by_gem(gem_name)
11
+ new(gem_name.gsub('-', '/').camelize)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module ApplicationStereotypes
5
+ class Base
6
+ module Detection
7
+ common_concern
8
+
9
+ module ClassMethods
10
+ # @return [Class<Avm::Sources::Base>, nil]
11
+ def detect(object)
12
+ return singleton_instance if
13
+ %w[name instance_class source_class].any? { |t| send("detect_by_#{t}?", object) }
14
+ end
15
+
16
+ # @return [Boolean]
17
+ def detect_by_instance_class?(object)
18
+ object.is_a?(::Class) && singleton_instance.instance_class == object
19
+ end
20
+
21
+ # @return [Boolean]
22
+ def detect_by_name?(object)
23
+ object.is_a?(::String) && singleton_instance.name == object
24
+ end
25
+
26
+ # @return [Boolean]
27
+ def detect_by_source_class?(object)
28
+ object.is_a?(::Class) && singleton_instance.source_class == object
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module ApplicationStereotypes
7
+ class Base
8
+ common_constructor :namespace_module, :instance_class, :source_class
9
+
10
+ # @return [String]
11
+ def name
12
+ namespace_module.name.demodulize
13
+ end
14
+
15
+ # @return [String]
16
+ def to_s
17
+ name
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module ApplicationStereotypes
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -1,16 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'avm/instances/entries'
4
+ require 'eac_ruby_utils/core_ext'
4
5
 
5
6
  module Avm
6
- module Instances
7
- class Application
7
+ module Applications
8
+ class Base
8
9
  include ::Avm::Instances::Entries
9
10
 
10
- attr_reader :id
11
-
12
- def initialize(id)
13
- @id = id.to_s
11
+ common_constructor :id do
12
+ self.id = id.to_s
14
13
  end
15
14
 
16
15
  def to_s
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Applications
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'avm/with_application_stereotype'
4
+ require 'avm/with_dynamic_runners'
3
5
  require 'eac_ruby_utils/require_sub'
4
6
  require 'eac_ruby_utils/simple_cache'
5
7
  require 'avm/instances/entries'
@@ -7,10 +9,13 @@ require 'avm/instances/entries'
7
9
  module Avm
8
10
  module Instances
9
11
  class Base
12
+ enable_abstract_methods
10
13
  enable_listable
11
14
  enable_simple_cache
12
15
  require_sub __FILE__, include_modules: true
13
16
  include ::Avm::Instances::Entries
17
+ include ::Avm::WithDynamicRunners
18
+ include ::Avm::WithApplicationStereotype
14
19
 
15
20
  lists.add_string :access, :local, :ssh
16
21
 
@@ -19,8 +24,8 @@ module Avm
19
24
  class << self
20
25
  def by_id(id)
21
26
  application_id, suffix = parse_id(id)
22
- require 'avm/instances/application'
23
- new(::Avm::Instances::Application.new(application_id), suffix)
27
+ require 'avm/applications/base'
28
+ new(::Avm::Applications::Base.new(application_id), suffix)
24
29
  end
25
30
 
26
31
  private
data/lib/avm/instances.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Avm
4
4
  module Instances
5
- require 'avm/instances/application'
5
+ require 'avm/applications/base'
6
6
  require 'avm/instances/entries'
7
7
  end
8
8
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/registry/application_stereotypes/stereotype_builder'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Registry
8
+ class ApplicationStereotypes
9
+ class BuildAvailable
10
+ enable_method_class
11
+
12
+ common_constructor :owner
13
+
14
+ def result
15
+ reset_buffer
16
+ read_instances_registry
17
+ read_sources_registry
18
+ buffer.values.map(&:build)
19
+ end
20
+
21
+ private
22
+
23
+ attr_accessor :buffer
24
+
25
+ def read_object(type, object)
26
+ buffer[object.stereotype_namespace_module] ||=
27
+ ::Avm::Registry::ApplicationStereotypes::StereotypeBuilder
28
+ .new(object.stereotype_namespace_module)
29
+ buffer[object.stereotype_namespace_module].add_object(type, object)
30
+ end
31
+
32
+ def read_instances_registry
33
+ ::Avm::Registry.instances.available.each { |instance| read_object(:instance, instance) }
34
+ end
35
+
36
+ def read_sources_registry
37
+ ::Avm::Registry.sources.available.each { |source| read_object(:source, source) }
38
+ end
39
+
40
+ def reset_buffer
41
+ self.buffer = {}
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/application_stereotypes/base'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Registry
8
+ class ApplicationStereotypes
9
+ class StereotypeBuilder
10
+ common_constructor :namespace_module
11
+
12
+ def add_object(type, object)
13
+ attr_method = "#{type}_class"
14
+ raise "#{attr_method} is already present" if send(attr_method).present?
15
+
16
+ send("#{attr_method}=", object)
17
+ end
18
+
19
+ # @return [Avm::ApplicationStereotypes::Base]
20
+ def build
21
+ ::Avm::ApplicationStereotypes::Base.new(namespace_module, instance_class, source_class)
22
+ end
23
+
24
+ private
25
+
26
+ attr_accessor :instance_class, :source_class
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Registry
7
+ class ApplicationStereotypes
8
+ require_sub __FILE__, require_dependency: true
9
+ enable_simple_cache
10
+
11
+ common_constructor :module_suffix
12
+
13
+ private
14
+
15
+ def available_uncached
16
+ build_available
17
+ end
18
+
19
+ # @return [Avm::Instances::Base, nil]
20
+ def class_detect(klass, detect_args)
21
+ r = ::Avm::Instances::Base.by_id(*detect_args)
22
+ r.application.stereotype.instance_class == klass ? r : nil
23
+ end
24
+
25
+ def detect(*registered_initialize_args)
26
+ detect_optional(*registered_initialize_args) ||
27
+ raise_not_found(*registered_initialize_args)
28
+ end
29
+
30
+ def detect_optional(*registered_initialize_args)
31
+ registered_modules.reverse.lazy
32
+ .map { |klass| class_detect(klass, registered_initialize_args) }.find(&:present?)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -5,18 +5,27 @@ require 'eac_ruby_utils/gems_registry'
5
5
 
6
6
  module Avm
7
7
  module Registry
8
- class Base
8
+ class FromGems
9
+ enable_abstract_methods
9
10
  enable_simple_cache
10
11
  common_constructor :module_suffix
11
12
 
13
+ def available
14
+ registered_modules.reject(&:abstract?)
15
+ end
16
+
17
+ def class_detect(_klass, _detect_args)
18
+ raise_abstract_method __method__
19
+ end
20
+
12
21
  def detect(*registered_initialize_args)
13
22
  detect_optional(*registered_initialize_args) ||
14
23
  raise_not_found(*registered_initialize_args)
15
24
  end
16
25
 
17
26
  def detect_optional(*registered_initialize_args)
18
- registered_modules.reverse.lazy.map { |klass| klass.new(*registered_initialize_args) }
19
- .find(&:valid?)
27
+ available.reverse.lazy
28
+ .map { |klass| class_detect(klass, registered_initialize_args) }.find(&:present?)
20
29
  end
21
30
 
22
31
  def provider_module_suffix
@@ -39,7 +48,7 @@ module Avm
39
48
 
40
49
  def raise_not_found(*args)
41
50
  raise("No registered module valid for #{args}" \
42
- " (Module suffix: #{module_suffix}, Available: #{registered_modules.join(', ')})")
51
+ " (Module suffix: #{module_suffix}, Available: #{available.join(', ')})")
43
52
  end
44
53
 
45
54
  def registered_modules_uncached
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/base'
4
+ require 'avm/registry/from_gems'
5
+
6
+ module Avm
7
+ module Registry
8
+ class Instances < ::Avm::Registry::FromGems
9
+ # @return [Avm::Instances::Base, nil]
10
+ def class_detect(klass, detect_args)
11
+ r = ::Avm::Instances::Base.by_id(*detect_args)
12
+ r.application.stereotype.instance_class == klass ? r : nil
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/registry/from_gems'
4
+
5
+ module Avm
6
+ module Registry
7
+ class Runners < ::Avm::Registry::FromGems
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/registry/with_path'
4
+
5
+ module Avm
6
+ module Registry
7
+ class Scms < ::Avm::Registry::WithPath
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/registry/with_path'
4
+
5
+ module Avm
6
+ module Registry
7
+ class Sources < ::Avm::Registry::WithPath
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/registry/from_gems'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Registry
8
+ class WithPath < ::Avm::Registry::FromGems
9
+ class Cache
10
+ enable_simple_cache
11
+ common_constructor :owner
12
+
13
+ def detect_optional(path)
14
+ return nil if path.root?
15
+ return cached_paths.fetch(path) if cached_paths.key?(path)
16
+
17
+ detected = owner.detect_optional(path)
18
+ detected = detect_optional(path.parent) if detected.blank?
19
+ cached_paths[path] = detected
20
+ detected
21
+ end
22
+
23
+ private
24
+
25
+ def cached_paths_uncached
26
+ {}
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,22 +1,48 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/registry/base'
3
+ require 'avm/registry/from_gems'
4
4
  require 'eac_ruby_utils/core_ext'
5
5
 
6
6
  module Avm
7
7
  module Registry
8
- class WithPath < ::Avm::Registry::Base
8
+ class WithPath < ::Avm::Registry::FromGems
9
+ require_sub __FILE__
10
+
11
+ # @return [Object, nil]
12
+ def class_detect(klass, detect_args)
13
+ r = klass.new(*detect_args)
14
+ r.valid? ? r : nil
15
+ end
16
+
9
17
  def detect_by_path(path)
10
18
  detect_by_path_optional(path) || raise_not_found(path)
11
19
  end
12
20
 
13
21
  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
22
+ on_cache do
23
+ cache.detect_optional(path)
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ attr_accessor :cache
30
+
31
+ def on_cache(&block)
32
+ cache.present? ? on_cache_with_cache(&block) : on_cache_with_no_cache(&block)
33
+ end
34
+
35
+ def on_cache_with_cache(&block)
36
+ block.call
37
+ end
38
+
39
+ def on_cache_with_no_cache(&block)
40
+ self.cache = ::Avm::Registry::WithPath::Cache.new(self)
41
+ begin
42
+ block.call
43
+ ensure
44
+ self.cache = nil
18
45
  end
19
- nil
20
46
  end
21
47
  end
22
48
  end
data/lib/avm/registry.rb CHANGED
@@ -7,14 +7,14 @@ module Avm
7
7
  module Registry
8
8
  require_sub __FILE__
9
9
  enable_listable
10
- lists.add_symbol :category, :instance_stereotypes, :runners, :scms, :sources
10
+ lists.add_symbol :category, :application_stereotypes, :instances, :runners, :scms, :sources
11
11
 
12
12
  WITH_PATH = [CATEGORY_SCMS, CATEGORY_SOURCES].freeze
13
13
 
14
14
  class << self
15
15
  enable_simple_cache
16
16
 
17
- # @return [Array<Avm::Registry::Base>]
17
+ # @return [Array<Avm::Registry::FromGems>]
18
18
  def registries
19
19
  lists.category.values.map { |c| send(c) }
20
20
  end
@@ -28,11 +28,7 @@ module Avm
28
28
  end
29
29
 
30
30
  def registry_class(category)
31
- if WITH_PATH.include?(category)
32
- ::Avm::Registry::WithPath
33
- else
34
- ::Avm::Registry::Base
35
- end
31
+ ::Avm::Registry.const_get(category.to_s.camelize)
36
32
  end
37
33
  end
38
34
  end
@@ -7,7 +7,7 @@ require 'avm/registry'
7
7
  .each do |registry|
8
8
  context "when registry is #{registry}" do
9
9
  it 'is not in the avm registry' do
10
- expect(registry.registered_modules).not_to include(described_class)
10
+ expect(registry.available).not_to include(described_class)
11
11
  end
12
12
  end
13
13
  end
@@ -9,8 +9,19 @@ module Avm
9
9
  module Sources
10
10
  class Base
11
11
  module Configuration
12
+ PARENT_CONFIGURATION_SUFFIX = %w[subs at].freeze
12
13
  CONFIGURATION_FILENAMES = %w[.avm.yml .avm.yaml].freeze
13
14
 
15
+ # @return [EacConfig::NodeEntry]
16
+ def configuration_entry(*entry_args)
17
+ parent_configuration.if_present do |v|
18
+ parent_entry = v.entry(*entry_args)
19
+ return parent_entry if parent_entry.found?
20
+ end
21
+
22
+ configuration.entry(*entry_args)
23
+ end
24
+
14
25
  # @return [EacRubyUtils::Envs::Command, nil]
15
26
  def configuration_value_to_env_command(value)
16
27
  configuration_value_to_shell_words(value).if_present { |v| env.command(v).chdir(path) }
@@ -25,13 +36,13 @@ module Avm
25
36
 
26
37
  # @return [Array<String>, nil]
27
38
  def read_configuration_as_shell_words(key)
28
- configuration_value_to_shell_words(configuration.entry(key).value)
39
+ configuration_value_to_shell_words(configuration_entry(key).value)
29
40
  end
30
41
 
31
42
  # Utility to read a configuration as a [EacRubyUtils::Envs::Command].
32
43
  # @return [EacRubyUtils::Envs::Command]
33
44
  def read_configuration_as_env_command(key)
34
- configuration_value_to_env_command(configuration.entry(key).value)
45
+ configuration_value_to_env_command(configuration_entry(key).value)
35
46
  end
36
47
 
37
48
  private
@@ -44,6 +55,16 @@ module Avm
44
55
  configuration_with_filename(CONFIGURATION_FILENAMES.first, false)
45
56
  end
46
57
 
58
+ # @return [String]
59
+ def parent_configuration_prefix
60
+ PARENT_CONFIGURATION_SUFFIX + [relative_path]
61
+ end
62
+
63
+ # @return [EacConfig::PrefixedPathNode]
64
+ def parent_configuration_uncached
65
+ parent.if_present { |v| v.configuration.with_prefix(parent_configuration_prefix) }
66
+ end
67
+
47
68
  # @return [EacConfig::YamlFileNode, nil]
48
69
  def configuration_with_filename(filename, needs_exist)
49
70
  file_path = path.join(filename)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/instances/application'
3
+ require 'avm/applications/base'
4
4
  require 'avm/instances/base'
5
5
 
6
6
  module Avm
@@ -16,7 +16,7 @@ module Avm
16
16
  private
17
17
 
18
18
  def application_uncached
19
- ::Avm::Instances::Application.new(path.basename)
19
+ ::Avm::Applications::Base.new(path.basename)
20
20
  end
21
21
 
22
22
  def instance_uncached
@@ -14,7 +14,7 @@ module Avm
14
14
  end
15
15
 
16
16
  def configured_locale
17
- configuration.entry(LOCALE_KEY).value
17
+ configuration_entry(LOCALE_KEY).value
18
18
  end
19
19
 
20
20
  def default_locale
@@ -6,11 +6,6 @@ module Avm
6
6
  module Sources
7
7
  class Base
8
8
  module Parent
9
- # @return [Avm::Sources::Base]
10
- def parent
11
- parent_by_option || parent_by_search
12
- end
13
-
14
9
  # @return [Avm::Sources::Base]
15
10
  def parent_by_option
16
11
  options[OPTION_PARENT]
@@ -18,12 +13,14 @@ module Avm
18
13
 
19
14
  # @return [Avm::Sources::Base]
20
15
  def parent_by_search
21
- parent_path = path.parent
22
- until parent_path.root?
23
- ::Avm::Registry.sources.detect_optional(parent_path).if_present { |v| return v }
24
- parent_path = parent_path.parent
25
- end
26
- nil
16
+ ::Avm::Registry.sources.detect_by_path_optional(path.parent)
17
+ end
18
+
19
+ private
20
+
21
+ # @return [Avm::Sources::Base]
22
+ def parent_uncached
23
+ parent_by_option || parent_by_search
27
24
  end
28
25
  end
29
26
  end
@@ -22,7 +22,7 @@ module Avm
22
22
 
23
23
  # @return [Array<String>]
24
24
  def configured_paths
25
- source.configuration.entry(configuration_key).value.if_present do |v|
25
+ source.configuration_entry(configuration_key).value.if_present do |v|
26
26
  v.split(SUBS_PATH_SEPARATOR)
27
27
  end
28
28
  end
@@ -18,12 +18,12 @@ module Avm
18
18
 
19
19
  # @return [Hash<String, EacRubyUtils::Envs::Command>, nil]
20
20
  def configured_test_commands
21
- configured_value_as_test_commands(configuration.entry(TEST_COMMANDS_KEY).value)
21
+ configured_value_as_test_commands(configuration_entry(TEST_COMMANDS_KEY).value)
22
22
  end
23
23
 
24
24
  # @return [Hash<String, EacRubyUtils::Envs::Command>, nil]
25
25
  def configured_value_as_test_commands(value)
26
- return nil if value.blank?
26
+ return nil if value.nil?
27
27
 
28
28
  [::EacRubyUtils::Envs::Command, ::Hash, ::Enumerable].each do |type|
29
29
  next unless value.is_a?(type)
@@ -45,8 +45,8 @@ module Avm
45
45
  # @return [Enumerable<EacRubyUtils::Envs::Command>]
46
46
  def test_commands
47
47
  configured_test_commands ||
48
- configured_value_as_test_commands(configured_test_command)
49
- default_test_commands
48
+ configured_value_as_test_commands(configured_test_command) ||
49
+ default_test_commands
50
50
  end
51
51
 
52
52
  protected
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'avm/registry'
4
4
  require 'avm/scms/null'
5
+ require 'avm/with_application_stereotype'
6
+ require 'avm/with_dynamic_runners'
5
7
  require 'eac_git'
6
8
  require 'eac_ruby_utils/core_ext'
7
9
 
@@ -9,6 +11,8 @@ module Avm
9
11
  module Sources
10
12
  class Base
11
13
  require_sub __FILE__, include_modules: true
14
+ include ::Avm::WithApplicationStereotype
15
+ include ::Avm::WithDynamicRunners
12
16
  compare_by :path
13
17
  enable_abstract_methods
14
18
  enable_simple_cache
@@ -8,6 +8,8 @@ module Avm
8
8
  module Sources
9
9
  module Tests
10
10
  class Builder
11
+ NO_TEST_TEST_NAME = 'no_test'
12
+
11
13
  require_sub __FILE__
12
14
  enable_immutable
13
15
 
@@ -33,7 +35,7 @@ module Avm
33
35
  # @return [Array<Avm::Sources::Tests::Single>]
34
36
  def available_units
35
37
  @available_units ||= ([main_source] + main_source.subs)
36
- .map { |a_source| create_unit(a_source) }
38
+ .flat_map { |a_source| create_source_units(a_source) }
37
39
  end
38
40
 
39
41
  def available_units_from_main
@@ -44,27 +46,31 @@ module Avm
44
46
  create_units(main_source.subs)
45
47
  end
46
48
 
49
+ # @return [Avm::Sources::Tests::Single]
50
+ def create_source_no_test_unit(source)
51
+ ::Avm::Sources::Tests::Single.new(self, source, NO_TEST_TEST_NAME,
52
+ source.env.command('true'))
53
+ end
54
+
47
55
  # @return [Array<Avm::Sources::Tests::Single>]
48
56
  def create_source_units(source)
49
- source.test_commands.map do |test_name, test_command|
57
+ tests = source.test_commands
58
+ return create_source_no_test_unit(source) unless tests.any?
59
+
60
+ tests.map do |test_name, test_command|
50
61
  ::Avm::Sources::Tests::Single.new(self, source, test_name, test_command)
51
62
  end
52
63
  end
53
64
 
54
- # @return [Avm::Sources::Tests::Single]
55
- def create_unit(source)
56
- ::Avm::Sources::Tests::Single.new(self, source)
57
- end
58
-
59
65
  # @return [Array<Avm::Sources::Tests::Single>]
60
66
  def create_units(sources)
61
67
  sources.flat_map { |a_source| create_source_units(a_source) }
62
68
  end
63
69
 
64
70
  # @return [Avm::Sources::Tests::Single]
65
- def create_unit_by_id(source_id)
66
- r = available_units.find { |unit| unit.id == source_id }
67
- return r if r
71
+ def create_units_by_id(source_id)
72
+ r = available_units.select { |unit| unit.source.relative_path.to_path == source_id.to_s }
73
+ return r if r.any?
68
74
 
69
75
  raise ::ArgumentError, "Source not found with ID=#{source_id}" \
70
76
  "(Available: #{available_units.map(&:id).join(', ')})"
@@ -72,7 +78,7 @@ module Avm
72
78
 
73
79
  # @return [Array<Avm::Sources::Tests::Single>]
74
80
  def select_units_from_ids
75
- include_ids.map { |source_id| create_unit_by_id(source_id) }
81
+ include_ids.flat_map { |source_id| create_units_by_id(source_id) }
76
82
  end
77
83
 
78
84
  # @return [Array<Avm::Sources::Tests::Single>]
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.24.0'
4
+ VERSION = '0.27.0'
5
5
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner_with/subcommands'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module WithApplicationStereotype
8
+ common_concern do
9
+ include ClassMethods
10
+ end
11
+
12
+ module ClassMethods
13
+ # @return [Module]
14
+ def stereotype_namespace_module
15
+ module_parent.module_parent
16
+ end
17
+ end
18
+
19
+ def stereotype_namespace_module
20
+ self.class.stereotype_namespace_module
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner_with/subcommands'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module WithDynamicRunners
8
+ # @return [Hash<String, EacCli::Runner>]
9
+ def extra_available_subcommands
10
+ extra_available_subcommands_from_runners_module
11
+ end
12
+
13
+ # @return [Hash<String, EacCli::Runner>]
14
+ def extra_available_subcommands_from_runners_module
15
+ self.class.ancestors.reverse.inject({}) do |a, e|
16
+ a.merge(RunnersFromModule.new(e).result)
17
+ end
18
+ end
19
+
20
+ class RunnersFromModule
21
+ enable_simple_cache
22
+ common_constructor :the_module
23
+
24
+ # @return [Hash<String, EacCli::Runner>]
25
+ def result
26
+ return {} if runners_module.blank?
27
+
28
+ ::EacCli::RunnerWith::Subcommands.subcommands_from_module(runners_module)
29
+ end
30
+
31
+ def runners_module_uncached
32
+ return nil if the_module.module_parent.blank?
33
+
34
+ begin
35
+ the_module.module_parent.const_get('Runners')
36
+ rescue ::NameError
37
+ nil
38
+ end
39
+ end
40
+ end
41
+ end
42
+ 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.24.0
4
+ version: 0.27.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-07-17 00:00:00.000000000 Z
11
+ date: 2022-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_cli
@@ -30,6 +30,20 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 0.27.6
33
+ - !ruby/object:Gem::Dependency
34
+ name: eac_config
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.9'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.9'
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: eac_docker
35
49
  requirement: !ruby/object:Gem::Requirement
@@ -181,6 +195,12 @@ extensions: []
181
195
  extra_rdoc_files: []
182
196
  files:
183
197
  - lib/avm.rb
198
+ - lib/avm/application_stereotypes.rb
199
+ - lib/avm/application_stereotypes/base.rb
200
+ - lib/avm/application_stereotypes/base/by_gem.rb
201
+ - lib/avm/application_stereotypes/base/detection.rb
202
+ - lib/avm/applications.rb
203
+ - lib/avm/applications/base.rb
184
204
  - lib/avm/data/instance.rb
185
205
  - lib/avm/data/instance/files_unit.rb
186
206
  - lib/avm/data/instance/package.rb
@@ -196,7 +216,6 @@ files:
196
216
  - lib/avm/docker/runner.rb
197
217
  - lib/avm/executables.rb
198
218
  - lib/avm/instances.rb
199
- - lib/avm/instances/application.rb
200
219
  - lib/avm/instances/base.rb
201
220
  - lib/avm/instances/base/auto_values.rb
202
221
  - lib/avm/instances/base/auto_values/access.rb
@@ -225,8 +244,16 @@ files:
225
244
  - lib/avm/launcher/publish/check_result.rb
226
245
  - lib/avm/path_string.rb
227
246
  - lib/avm/registry.rb
228
- - lib/avm/registry/base.rb
247
+ - lib/avm/registry/application_stereotypes.rb
248
+ - lib/avm/registry/application_stereotypes/build_available.rb
249
+ - lib/avm/registry/application_stereotypes/stereotype_builder.rb
250
+ - lib/avm/registry/from_gems.rb
251
+ - lib/avm/registry/instances.rb
252
+ - lib/avm/registry/runners.rb
253
+ - lib/avm/registry/scms.rb
254
+ - lib/avm/registry/sources.rb
229
255
  - lib/avm/registry/with_path.rb
256
+ - lib/avm/registry/with_path/cache.rb
230
257
  - lib/avm/result.rb
231
258
  - lib/avm/rspec.rb
232
259
  - lib/avm/rspec/setup.rb
@@ -246,7 +273,6 @@ files:
246
273
  - lib/avm/sources/base/instance.rb
247
274
  - lib/avm/sources/base/locale.rb
248
275
  - lib/avm/sources/base/parent.rb
249
- - lib/avm/sources/base/runners.rb
250
276
  - lib/avm/sources/base/subs.rb
251
277
  - lib/avm/sources/base/subs_paths.rb
252
278
  - lib/avm/sources/base/testing.rb
@@ -260,6 +286,8 @@ files:
260
286
  - lib/avm/sync.rb
261
287
  - lib/avm/version.rb
262
288
  - lib/avm/version_number.rb
289
+ - lib/avm/with_application_stereotype.rb
290
+ - lib/avm/with_dynamic_runners.rb
263
291
  homepage:
264
292
  licenses: []
265
293
  metadata: {}
@@ -1,47 +0,0 @@
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