avm 0.19.0 → 0.22.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: 60254779c64e435b8f853ab931907a47eefb974428e2298dc82b2f6d308d642a
4
- data.tar.gz: 8c054b755c9882ed5b1faaa0c521031edf3551139d04259e0e11895844b4ef63
3
+ metadata.gz: '0165809370dba684b9d456d8d28447e0d8cf625b9abe8f15a6b2d47aae905518'
4
+ data.tar.gz: f8f75c35fd20364008a777023f542cb505c4ee0774c093c1069d452a2656becf
5
5
  SHA512:
6
- metadata.gz: 3b7aadec66e69a23688c07dffd62f05d1579a1b14c90f57f2e5e6b2caf460e59b394ac62fe60178428100caf5359ab04ae21fecf958748dd01553129cb7d3304
7
- data.tar.gz: c7eddaff6582abdbbb12d6b09a919b199505c1d4189fc8a6696eec61c39f5c41d3b4670d92278b9d30e049b49a99271b0826cb4d079c1b6ab2190424029d0274
6
+ metadata.gz: ba30dc2ecb69636de16b65c6b2dc2b51e2e7014dec33f7958d9b8451cf515435868176d40570693e7f61b7e56a9896e0c40da3e98ce9e2c770acb2d06c339661
7
+ data.tar.gz: d54c9c0ba6c1fcbcd2f2dba2eff4fc360a300c0eccf6d801989a1f11eb44dd32ae740a6dc122768292dbc1a59e0c51773d2bf78770503d7ce51ccfa7bf91fe91
@@ -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
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_config/yaml_file_node'
3
4
  require 'eac_ruby_utils/core_ext'
4
5
  require 'eac_ruby_utils/yaml'
5
6
  require 'shellwords'
@@ -8,23 +9,39 @@ module Avm
8
9
  module Sources
9
10
  class Base
10
11
  module Configuration
12
+ CONFIGURATION_FILENAMES = %w[.avm.yml .avm.yaml].freeze
13
+
11
14
  # @return [Array<String>, nil]
12
15
  def read_configuration_as_shell_words(key)
13
- configuration[key].if_present do |v|
16
+ configuration.entry(key).value.if_present do |v|
14
17
  v.is_a?(::Enumerable) ? v.map(&:to_s) : ::Shellwords.split(v.to_s)
15
18
  end
16
19
  end
17
20
 
21
+ # Utility to read a configuration as a [EacRubyUtils::Envs::Command].
22
+ # @return [EacRubyUtils::Envs::Command]
23
+ def read_configuration_as_env_command(key)
24
+ read_configuration_as_shell_words(key).if_present do |v|
25
+ env.command(v).chdir(path)
26
+ end
27
+ end
28
+
18
29
  private
19
30
 
20
- # @return [Hash]
31
+ # @return [EacConfig::YamlFileNode]
21
32
  def configuration_uncached
22
- ::Avm::Sources::Configuration::FILENAMES.each do |filename|
23
- file_path = path.join(filename)
24
- return ::EacRubyUtils::Yaml.load_file(file_path).with_indifferent_access if
25
- file_path.exist?
33
+ CONFIGURATION_FILENAMES.each do |filename|
34
+ configuration_with_filename(filename, true)
26
35
  end
27
- {}
36
+ configuration_with_filename(CONFIGURATION_FILENAMES.first, false)
37
+ end
38
+
39
+ # @return [EacConfig::YamlFileNode, nil]
40
+ def configuration_with_filename(filename, needs_exist)
41
+ file_path = path.join(filename)
42
+ return ::EacConfig::YamlFileNode.new(file_path) if !needs_exist || file_path.exist?
43
+
44
+ nil
28
45
  end
29
46
 
30
47
  # @return [Avm::Sources::Configuration]
@@ -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,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/sources/base/subs_paths'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Sources
8
+ class Base
9
+ module Subs
10
+ CONFIGURATION_SUBS_EXCLUDE_PATHS_KEY = 'subs.exclude_path'
11
+ CONFIGURATION_SUBS_INCLUDE_PATHS_KEY = 'subs.include_path'
12
+ SUBS_EXCLUDE_PATHS_DEFAULT = [].freeze
13
+ SUBS_INCLUDE_PATHS_DEFAULT = ['sub/*'].freeze
14
+
15
+ # @return [Enumerable<Avm::Sources::Base>]
16
+ def subs
17
+ subs_paths_to_search
18
+ .map { |sub_path| ::Avm::Registry.sources.detect_optional(sub_path, parent: self) }
19
+ .reject(&:blank?)
20
+ .sort_by { |sub| [sub.path] }
21
+ end
22
+
23
+ def subs_paths_to_search
24
+ subs_include_paths.flat_map do |subs_include_path|
25
+ ::Pathname.glob(path.join(subs_include_path)).reject do |sub_path|
26
+ subs_exclude_paths.any? do |subs_exclude_path|
27
+ sub_path.fnmatch?(path.join(subs_exclude_path).to_path)
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ %i[include exclude].each do |type|
34
+ %i[path paths configured_paths default_paths].each do |method_suffix|
35
+ obj_method_name = "subs_#{type}_path_obj"
36
+
37
+ define_method "subs_#{type}_#{method_suffix}" do
38
+ send(obj_method_name).send(method_suffix)
39
+ end
40
+
41
+ define_method "#{obj_method_name}_uncached" do
42
+ ::Avm::Sources::Base::SubsPaths.new(
43
+ self,
44
+ self.class.const_get("CONFIGURATION_SUBS_#{type}_PATHS_KEY".upcase),
45
+ self.class.const_get("SUBS_#{type}_PATHS_DEFAULT".upcase)
46
+ )
47
+ end
48
+
49
+ private "#{obj_method_name}_uncached" # rubocop:disable Style/AccessModifierDeclarations
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Sources
7
+ class Base
8
+ class SubsPaths
9
+ SUBS_PATH_SEPARATOR = ':'
10
+
11
+ common_constructor :source, :configuration_key, :default_paths
12
+
13
+ # @return [String]
14
+ def path
15
+ paths.join(SUBS_PATH_SEPARATOR)
16
+ end
17
+
18
+ # @return [Array<String>]
19
+ def paths
20
+ configured_paths || default_paths
21
+ end
22
+
23
+ # @return [Array<String>]
24
+ def configured_paths
25
+ source.configuration.entry(configuration_key).value.if_present do |v|
26
+ v.split(SUBS_PATH_SEPARATOR)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -6,6 +6,12 @@ module Avm
6
6
  module Sources
7
7
  class Base
8
8
  module Testing
9
+ TEST_COMMAND_KEY = 'test.command'
10
+
11
+ def configured_test_command
12
+ read_configuration_as_env_command(TEST_COMMAND_KEY)
13
+ end
14
+
9
15
  # @return [Avm::Sources::Tester]
10
16
  def tester
11
17
  tester_class.new(self)
@@ -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,7 +21,15 @@ module Avm
20
21
 
21
22
  abstract_methods :update, :valid?
22
23
 
23
- delegate :locale, to: :old_configuration
24
+ # @return [EacRubyUtils::Envs::LocalEnv]
25
+ def env
26
+ ::EacRubyUtils::Envs::LocalEnv.new
27
+ end
28
+
29
+ # @return [Hash<String, Class>]
30
+ def extra_available_subcommands
31
+ {}
32
+ end
24
33
 
25
34
  # @return [Pathname]
26
35
  def relative_path
@@ -33,16 +42,11 @@ module Avm
33
42
  "#{self.class}[#{path}]"
34
43
  end
35
44
 
36
- # @return [Enumerable<Avm::Sources::Base>]
37
- def subs
38
- scm.subs.map { |subrepo| ::Avm::Registry.sources.detect(subrepo.path, parent: self) }
39
- end
40
-
41
45
  private
42
46
 
43
47
  # @return [Avm::Scms::Base]
44
48
  def scm_uncached
45
- ::Avm::Registry.scms.detect(path)
49
+ ::Avm::Registry.scms.detect_optional(path) || ::Avm::Scms::Null.new(path)
46
50
  end
47
51
  end
48
52
  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.19.0'
4
+ VERSION = '0.22.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.19.0
4
+ version: 0.22.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-14 00:00:00.000000000 Z
11
+ date: 2022-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_cli
@@ -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,12 +244,13 @@ 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/subs.rb
250
+ - lib/avm/sources/base/subs_paths.rb
246
251
  - lib/avm/sources/base/testing.rb
247
252
  - lib/avm/sources/configuration.rb
248
- - lib/avm/sources/configuration/locale.rb
249
253
  - lib/avm/sources/configuration/rubocop.rb
250
- - lib/avm/sources/configuration/tests.rb
251
254
  - lib/avm/sources/tester.rb
252
255
  - lib/avm/sources/tests.rb
253
256
  - lib/avm/sources/tests/builder.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