avm 0.26.0 → 0.27.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: 409db17d04ee296956e9770e61a5f65919fbf2b0c8bea4efae0ed68fb169572a
4
- data.tar.gz: 3c7e6ea386a2527ed86c3bb9ef8a71b1767d17a204d48b1ecc3b74c015772328
3
+ metadata.gz: 6e8acabcae2be2a5ede0d16f23948a2fde0073eadcb0aa4affec5af992db9ee9
4
+ data.tar.gz: e2a626b43d125f5f3c79173753e8a94edf8d1894aca17ba5299a94a5e9f3639c
5
5
  SHA512:
6
- metadata.gz: 302b99ff7495bf6c3f4624432e63f1f2668f8b5d2a2ac91bc721f3206baf9595520c192fa4ead326ad7ce3c646253ca7f1a71a48ee1b11080e1898efe4fef5f8
7
- data.tar.gz: 7b85ae2c2a03f3abfeed96924ab6e0180d17709ec422cd3b0638f7075cc750c25a8118d7654554ecfe80519fdeb505da9aa720f2109fdf7bcacfdf7bf884d141
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
@@ -1,11 +1,11 @@
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
9
  class Cache
10
10
  enable_simple_cache
11
11
  common_constructor :owner
@@ -1,13 +1,19 @@
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
9
  require_sub __FILE__
10
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
+
11
17
  def detect_by_path(path)
12
18
  detect_by_path_optional(path) || raise_not_found(path)
13
19
  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
@@ -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
@@ -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
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.26.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.26.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-21 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
@@ -195,6 +195,12 @@ extensions: []
195
195
  extra_rdoc_files: []
196
196
  files:
197
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
198
204
  - lib/avm/data/instance.rb
199
205
  - lib/avm/data/instance/files_unit.rb
200
206
  - lib/avm/data/instance/package.rb
@@ -210,7 +216,6 @@ files:
210
216
  - lib/avm/docker/runner.rb
211
217
  - lib/avm/executables.rb
212
218
  - lib/avm/instances.rb
213
- - lib/avm/instances/application.rb
214
219
  - lib/avm/instances/base.rb
215
220
  - lib/avm/instances/base/auto_values.rb
216
221
  - lib/avm/instances/base/auto_values/access.rb
@@ -239,7 +244,14 @@ files:
239
244
  - lib/avm/launcher/publish/check_result.rb
240
245
  - lib/avm/path_string.rb
241
246
  - lib/avm/registry.rb
242
- - 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
243
255
  - lib/avm/registry/with_path.rb
244
256
  - lib/avm/registry/with_path/cache.rb
245
257
  - lib/avm/result.rb
@@ -261,7 +273,6 @@ files:
261
273
  - lib/avm/sources/base/instance.rb
262
274
  - lib/avm/sources/base/locale.rb
263
275
  - lib/avm/sources/base/parent.rb
264
- - lib/avm/sources/base/runners.rb
265
276
  - lib/avm/sources/base/subs.rb
266
277
  - lib/avm/sources/base/subs_paths.rb
267
278
  - lib/avm/sources/base/testing.rb
@@ -275,6 +286,8 @@ files:
275
286
  - lib/avm/sync.rb
276
287
  - lib/avm/version.rb
277
288
  - lib/avm/version_number.rb
289
+ - lib/avm/with_application_stereotype.rb
290
+ - lib/avm/with_dynamic_runners.rb
278
291
  homepage:
279
292
  licenses: []
280
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