avm 0.28.0 → 0.29.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: 0d4a230abab5f14e443e55426f5deb3fa99d8570d57714c5128c50d3dff3340a
4
- data.tar.gz: 71c879c6ee9fd1b3e3550142c9b78bfc101f8b863ac5ef812366cc3ff66e7c8d
3
+ metadata.gz: 2c59abe8a0046009874c49f168a3fba854d33721aaaf0bfbb95d96c0556c9aae
4
+ data.tar.gz: 8308f974d093782ed03f490365580fa4e5c838cd55da3c76fd4edf6972f59ccf
5
5
  SHA512:
6
- metadata.gz: cda7f5840e1d6ddf4c49732b9205b0c6ee9f31afa0d4ecfa41b343a96e9423704a76520544db021598567894b3a157ddbf034a892fc25be7792cd3bb47077666
7
- data.tar.gz: 566e375d67d75cc9dfd8de54b1839e4e85308b37dd34e9a9b337114dca02d8808fbdef7d888cc9e348c65f7316bfdd542c540bf204c3f4316d11a2767bac5fef
6
+ metadata.gz: 3544c95b8ffef42a7e9c8d1ad9e16f6984c945e861e2d5b0ce48c5744295087d5941dfa3c9191aefd96703762b2704cb630346f109a4c1348560e4361011b3f9
7
+ data.tar.gz: bbe9fb54467880e6b69d3954d79c72cac7cd541a300761ebc8cde38b234e5eead3febc889b81871d8079cf4ba95ec33b781ddf26d2ade447660a1c31e03c7486
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/registry'
4
+
5
+ module Avm
6
+ module Applications
7
+ class Base
8
+ module Stereotype
9
+ # @return [Avm::ApplicationStereotypes::Base, nil]
10
+ def stereotype_by_configuration
11
+ entry('stereotype').optional_value.if_present do |v|
12
+ ::Avm::Registry.application_stereotypes.detect(v)
13
+ end
14
+ end
15
+
16
+ # @return [Avm::ApplicationStereotypes::Base, nil]
17
+ def stereotype_by_source
18
+ ::Avm::Registry.application_stereotypes.detect_optional(local_source.class)
19
+ end
20
+
21
+ private
22
+
23
+ # @return [Avm::ApplicationStereotypes::Base]
24
+ def stereotype_uncached
25
+ stereotype_by_configuration || stereotype_by_source ||
26
+ raise("Could not find stereotype for application \"#{self}\"")
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,13 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'avm/instances/entries'
4
+ require 'avm/registry'
4
5
  require 'eac_ruby_utils/core_ext'
5
6
 
6
7
  module Avm
7
8
  module Applications
8
9
  class Base
10
+ enable_simple_cache
11
+ require_sub __FILE__, include_modules: true
9
12
  include ::Avm::Instances::Entries
10
13
 
14
+ LOCAL_INSTANCE_SUFFIX = 'dev'
15
+
11
16
  common_constructor :id do
12
17
  self.id = id.to_s
13
18
  end
@@ -23,6 +28,18 @@ module Avm
23
28
  def name
24
29
  entry(::Avm::Instances::EntryKeys::NAME).read
25
30
  end
31
+
32
+ private
33
+
34
+ # @return [Avm::Instances::Base]
35
+ def local_instance_uncached
36
+ instance(LOCAL_INSTANCE_SUFFIX)
37
+ end
38
+
39
+ # @return [Avm::Sources::Base]
40
+ def local_source_uncached
41
+ ::Avm::Registry.sources.detect(local_instance.fs_path)
42
+ end
26
43
  end
27
44
  end
28
45
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'avm/instances/base'
4
+ require 'avm/sources/base'
3
5
  require 'eac_ruby_utils/core_ext'
4
6
 
5
7
  module Avm
@@ -10,26 +12,40 @@ module Avm
10
12
 
11
13
  common_constructor :module_suffix
12
14
 
15
+ def detect(obj)
16
+ detect_optional(obj) || raise_not_found(obj)
17
+ end
18
+
19
+ def detect_optional(obj)
20
+ detect_by_instance_class(obj) || detect_by_source_class(obj) || detecy_by_name(obj)
21
+ end
22
+
13
23
  private
14
24
 
15
25
  def available_uncached
16
26
  build_available
17
27
  end
18
28
 
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
29
+ def detect_by_instance_class(obj)
30
+ return nil unless obj.is_a?(::Class) && obj < ::Avm::Instances::Base
31
+
32
+ available.find { |a| a.instance_class == obj }
23
33
  end
24
34
 
25
- def detect(*registered_initialize_args)
26
- detect_optional(*registered_initialize_args) ||
27
- raise_not_found(*registered_initialize_args)
35
+ def detecy_by_name(obj)
36
+ return nil unless obj.is_a?(::String)
37
+
38
+ available.find { |a| a.name == obj }
39
+ end
40
+
41
+ def detect_by_source_class(obj)
42
+ return nil unless obj.is_a?(::Class) && obj < ::Avm::Sources::Base
43
+
44
+ available.find { |a| a.source_class == obj }
28
45
  end
29
46
 
30
- def detect_optional(*registered_initialize_args)
31
- registered_modules.reverse.lazy
32
- .map { |klass| class_detect(klass, registered_initialize_args) }.find(&:present?)
47
+ def raise_not_found(obj)
48
+ raise("No registered module valid for #{obj} (Available: #{available.join(', ')})")
33
49
  end
34
50
  end
35
51
  end
@@ -9,7 +9,7 @@ module Avm
9
9
  # @return [Avm::Instances::Base, nil]
10
10
  def class_detect(klass, detect_args)
11
11
  r = ::Avm::Instances::Base.by_id(*detect_args)
12
- r.application.stereotype.instance_class == klass ? r : nil
12
+ r.application.stereotype.instance_class == klass ? klass.by_id(*detect_args) : nil
13
13
  end
14
14
  end
15
15
  end
data/lib/avm/scms/base.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'avm/with_application_stereotype'
3
4
  require 'eac_ruby_utils/core_ext'
4
5
 
5
6
  module Avm
@@ -7,6 +8,7 @@ module Avm
7
8
  class Base
8
9
  enable_abstract_methods
9
10
  enable_simple_cache
11
+ include ::Avm::WithApplicationStereotype
10
12
  abstract_methods :update, :valid?
11
13
  common_constructor :path do
12
14
  self.path = path.to_pathname
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.28.0'
4
+ VERSION = '0.29.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.28.0
4
+ version: 0.29.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-25 00:00:00.000000000 Z
11
+ date: 2022-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_cli
@@ -197,10 +197,9 @@ files:
197
197
  - lib/avm.rb
198
198
  - lib/avm/application_stereotypes.rb
199
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
200
  - lib/avm/applications.rb
203
201
  - lib/avm/applications/base.rb
202
+ - lib/avm/applications/base/stereotype.rb
204
203
  - lib/avm/data/instance.rb
205
204
  - lib/avm/data/instance/files_unit.rb
206
205
  - lib/avm/data/instance/package.rb
@@ -1,17 +0,0 @@
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
@@ -1,34 +0,0 @@
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