avm 0.59.0 → 0.61.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: 2e515ae3c2a7c5ce6fa8d620589e359aeb2568edd75b554932adb0a666f0ff8f
4
- data.tar.gz: 0ca8ac3456a4f99106d7e91d9429936365707b9ff68e20c0f8f36ba19074fc39
3
+ metadata.gz: fbd9a676670802e3c3904a555bc7255ab8637a1b474131e6f39190192d47d64d
4
+ data.tar.gz: 8f743999b2b25fe740cd813356e9104d9b29dcf03968c7a300afb31385babe83
5
5
  SHA512:
6
- metadata.gz: c3afecc85ab9c116a136758af1a0e8dbf889665eb09a6348f6be0c0e62da42bbd1073c64c19b4c3cece99bc57aae1d40faf645810c2f00fa9d2b9256ffc9d815
7
- data.tar.gz: 9771384b7caf46ad06478e2dc6d3d6a1a1f525baf66fdef65fb4e49e22fa4be258bc786372208e9ed8b572bb978c33ad11b9a8f8ae605522c0dbc1deab194213
6
+ metadata.gz: 1a96c7da39855abf2991b203b697ff69e61d4bdb4b322bebccf06066df2e59ab843d3bc5ecefc2e3a3011d7c514ec1854635d98e8d116089a55075bd7d07e166
7
+ data.tar.gz: a066bec86aed66c6f2d8bd6f849534551c684340bc61fa67da7a94dd4fdcffc4ffc43b33cb237f184f20a418232587f762bea578f743095fd2eeb2155527c83e
@@ -8,6 +8,7 @@ module Avm
8
8
  module FileFormats
9
9
  class Base
10
10
  enable_abstract_methods
11
+ compare_by :class
11
12
 
12
13
  def apply(files)
13
14
  old_content = Hash[files.map { |f| [f, File.read(f)] }]
@@ -15,6 +16,12 @@ module Avm
15
16
  files.map { |f| build_file_result(f, old_content[f]) }
16
17
  end
17
18
 
19
+ # @param path [Pathname]
20
+ # @return [Avm::FileFormats::FileWith]
21
+ def file_resource_name(path)
22
+ path.to_pathname.to_path
23
+ end
24
+
18
25
  def name
19
26
  self.class.name.demodulize
20
27
  end
@@ -50,19 +50,9 @@ module Avm
50
50
  @result = []
51
51
  end
52
52
 
53
+ # @return [Avm::FileFormats::Base, nil]
53
54
  def find_format(file)
54
- formats.each do |c|
55
- return c if c.match?(file)
56
- end
57
- nil
58
- end
59
-
60
- def formats_uncached
61
- formats_from_registry
62
- end
63
-
64
- def formats_from_registry
65
- ::Avm::Registry.file_formats.available.reverse.map(&:new)
55
+ ::Avm::Registry.file_formats.detect_optional(file)
66
56
  end
67
57
 
68
58
  def search_files
@@ -5,6 +5,10 @@ require 'avm/registry/from_gems'
5
5
  module Avm
6
6
  module Registry
7
7
  class FileFormats < ::Avm::Registry::FromGems
8
+ # @return [Avm::FileFormats::Base]
9
+ def class_detect(klass, detect_args)
10
+ klass.new if klass.new.match?(detect_args.first)
11
+ end
8
12
  end
9
13
  end
10
14
  end
@@ -7,8 +7,8 @@ module Avm
7
7
  module Rspec
8
8
  module Setup
9
9
  require_sub __FILE__
10
- EXAMPLES = %w[avm_file_formats_with_fixtures avm_source_generated entries_values
11
- in_avm_registry not_in_avm_registry].freeze
10
+ EXAMPLES = %w[avm_file_formats_with_fixtures avm_file_format_file_resource_name
11
+ avm_source_generated entries_values in_avm_registry not_in_avm_registry].freeze
12
12
 
13
13
  def self.extended(obj)
14
14
  obj.setup_examples
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ ::RSpec.shared_examples 'avm_file_format_file_resource_name' do |input_expected|
6
+ describe '#file_resource_name' do
7
+ input_expected.each do |path, expected_resource_name|
8
+ context "when path is \"#{path}\"" do
9
+ let(:instance) { described_class.new }
10
+
11
+ it { expect(instance.file_resource_name(path)).to eq(expected_resource_name) }
12
+ end
13
+ end
14
+ end
15
+ end
@@ -7,13 +7,14 @@ module Avm
7
7
  module AutoCommit
8
8
  class FileResourceName
9
9
  require_sub __FILE__, include_modules: true
10
+ enable_simple_cache
10
11
  common_constructor :source_root, :path do
11
12
  self.source_root = source_root.to_pathname
12
13
  self.path = path.to_pathname
13
14
  end
14
15
 
15
16
  def class_name
16
- ruby_class_name || relative_path.to_path
17
+ file_format.file_resource_name(path)
17
18
  end
18
19
 
19
20
  def commit_message
@@ -25,6 +26,13 @@ module Avm
25
26
  def relative_path
26
27
  path.expand_path.relative_path_from(source_root.expand_path)
27
28
  end
29
+
30
+ private
31
+
32
+ # @return [Avm::FileFormats::Base]
33
+ def file_format_uncached
34
+ ::Avm::Registry.file_formats.detect(path)
35
+ end
28
36
  end
29
37
  end
30
38
  end
@@ -16,6 +16,13 @@ module Avm
16
16
  raise_abstract_method __method__
17
17
  end
18
18
 
19
+ # @param commit_to_reset [Avm::Scms::Commit]
20
+ # @param commit_info [Avm::Scms::CommitInfo]
21
+ # @return [Avm::Scms::Commit]
22
+ def reset_and_commit(_commit_to_reset, _commit_info)
23
+ raise_abstract_method __method__
24
+ end
25
+
19
26
  # @param commit_info [Avm::Scms::CommitInfo]
20
27
  # @return [Avm::Scms::Commit]
21
28
  def run_commit(_commit_info)
@@ -5,6 +5,19 @@ require 'eac_ruby_utils/core_ext'
5
5
  module Avm
6
6
  module Scms
7
7
  class CommitInfo
8
+ class << self
9
+ # @param source [Avm::Scms::CommitInfo, String]
10
+ # @return [Avm::Scms::CommitInfo]
11
+ def assert(source)
12
+ return source if source.is_a?(self)
13
+ return new if source.nil?
14
+ return new.message(source) if source.is_a?(::String)
15
+ return assert(source.call) if source.is_a?(::Proc)
16
+
17
+ raise "Unmapped assertion for #{source.to_debug}"
18
+ end
19
+ end
20
+
8
21
  enable_immutable
9
22
 
10
23
  immutable_accessor :fixup, :message
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/scms/base'
4
+ require 'avm/scms/commit'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module Avm
8
+ module Scms
9
+ class Null < ::Avm::Scms::Base
10
+ class Commit < ::Avm::Scms::Commit
11
+ common_constructor :scm
12
+ end
13
+ end
14
+ end
15
+ end
data/lib/avm/scms/null.rb CHANGED
@@ -6,6 +6,13 @@ require 'eac_ruby_utils/core_ext'
6
6
  module Avm
7
7
  module Scms
8
8
  class Null < ::Avm::Scms::Base
9
+ require_sub __FILE__
10
+
11
+ # @return [Avm::Scms::Null::Commit]
12
+ def head_commit
13
+ @head_commit ||= Avm::Scms::Null::Commit.new(self)
14
+ end
15
+
9
16
  def update
10
17
  # Do nothing
11
18
  end
@@ -22,6 +22,13 @@ module Avm
22
22
  configuration.entry(*entry_args)
23
23
  end
24
24
 
25
+ # The possible absolute paths for configuration files.
26
+ #
27
+ # @return [Array<Pathname>]
28
+ def configuration_paths
29
+ CONFIGURATION_FILENAMES.map { |filename| path.join(filename) }
30
+ end
31
+
25
32
  # @return [EacRubyUtils::Envs::Command, nil]
26
33
  def configuration_value_to_env_command(value)
27
34
  return value if value.is_a?(::EacRubyUtils::Envs::Command)
@@ -51,10 +58,10 @@ module Avm
51
58
 
52
59
  # @return [EacConfig::YamlFileNode]
53
60
  def configuration_uncached
54
- CONFIGURATION_FILENAMES.each do |filename|
55
- configuration_with_filename(filename, true)
61
+ configuration_paths.each do |config_path|
62
+ configuration_with_filename(config_path, true)
56
63
  end
57
- configuration_with_filename(CONFIGURATION_FILENAMES.first, false)
64
+ configuration_with_filename(configuration_paths.first, false)
58
65
  end
59
66
 
60
67
  # @return [String]
@@ -68,9 +75,8 @@ module Avm
68
75
  end
69
76
 
70
77
  # @return [EacConfig::YamlFileNode, nil]
71
- def configuration_with_filename(filename, needs_exist)
72
- file_path = path.join(filename)
73
- return ::EacConfig::YamlFileNode.new(file_path) if !needs_exist || file_path.exist?
78
+ def configuration_with_filename(config_path, needs_exist)
79
+ return ::EacConfig::YamlFileNode.new(config_path) if !needs_exist || config_path.exist?
74
80
 
75
81
  nil
76
82
  end
@@ -20,6 +20,13 @@ module Avm
20
20
  def default_locale
21
21
  ::I18n.default_locale
22
22
  end
23
+
24
+ # @param entry_suffix [String]
25
+ # @param values [Hash]
26
+ # @return [String]
27
+ def i18n_translate(entry_suffix, values = {})
28
+ self.class.i18n_translate(entry_suffix, values.merge(__locale: locale))
29
+ end
23
30
  end
24
31
  end
25
32
  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
+ module Organizational
9
+ DEFAULT_ORGANIZATIONAL = false
10
+ ORGANIZATIONAL_KEY = 'organizational'
11
+
12
+ # @return [Boolean]
13
+ def organizational?
14
+ if organizational_entry.found?
15
+ organizational_entry.value.to_bool
16
+ else
17
+ default_organizational
18
+ end
19
+ end
20
+
21
+ def organizational_entry
22
+ configuration.entry(ORGANIZATIONAL_KEY)
23
+ end
24
+
25
+ # @return [Boolean]
26
+ def default_organizational
27
+ DEFAULT_ORGANIZATIONAL
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Sources
7
+ class Base
8
+ module Update
9
+ # To override in subclasses.
10
+ def on_sub_updated
11
+ # Do nothing
12
+ end
13
+
14
+ def update
15
+ update_self
16
+ update_subs
17
+ end
18
+
19
+ def update_self
20
+ scm.commit_if_change(-> { update_self_commit_message }) do
21
+ update_self_content
22
+ parent.if_present(&:on_sub_updated)
23
+ end
24
+ end
25
+
26
+ # Update source self content.
27
+ #
28
+ # To override in subclasses.
29
+ def update_self_content
30
+ # Do nothing
31
+ end
32
+
33
+ def update_self_commit_message
34
+ i18n_translate(__method__)
35
+ end
36
+
37
+ def update_subs
38
+ subs.each { |sub| update_sub(sub) }
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,57 @@
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 UpdateSub
9
+ enable_method_class
10
+
11
+ common_constructor :source, :sub
12
+
13
+ def result
14
+ update_version
15
+ return unless sub.organizational?
16
+
17
+ sub.update
18
+ end
19
+
20
+ private
21
+
22
+ def update_version
23
+ base_commit = source.scm.head_commit
24
+ sub.scm.update
25
+ on_update_version_commit_change(base_commit) unless base_commit == source.scm.head_commit
26
+ end
27
+
28
+ def on_update_version_commit_change(base_commit)
29
+ source.on_sub_updated if no_scm_updated?
30
+ source.scm.reset_and_commit(base_commit, update_version_commit_info)
31
+ end
32
+
33
+ def no_scm_updated?
34
+ source.scm.head_commit.no_scm_changed_files.any?
35
+ end
36
+
37
+ # @param commit_info [Avm::Scms::CommitInfo]
38
+ def update_version_commit_info
39
+ Avm::Scms::CommitInfo.new.message(
40
+ no_scm_updated? ? update_version_no_scm_message : update_version_scm_message
41
+ )
42
+ end
43
+
44
+ # @return [String]
45
+ def update_version_no_scm_message
46
+ source.i18n_translate(__method__, application_id: sub.application_id,
47
+ path: sub.relative_path, version: sub.version)
48
+ end
49
+
50
+ # @return [String]
51
+ def update_version_scm_message
52
+ sub.scm.i18n_translate(__method__)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/sources/base'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Sources
8
+ class Base
9
+ module VersionBump
10
+ # @return [Avm::Scms::Commit, nil]
11
+ def version_bump(target_version)
12
+ scm.commit_if_change(version_bump_commit_message(target_version)) do
13
+ version_bump_do_changes(target_version)
14
+ parent.if_present(&:on_sub_updated)
15
+ end
16
+ end
17
+
18
+ # @return [String]
19
+ def version_bump_commit_message(target_version)
20
+ i18n_translate(__method__, version: target_version, __locale: locale)
21
+ end
22
+
23
+ def version_bump_do_changes(_target_version)
24
+ raise_abstract_method(__METHOD__)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -23,7 +23,7 @@ module Avm
23
23
  self.options = ::Avm::Sources::Base.lists.option.hash_keys_validate!(options)
24
24
  end
25
25
 
26
- abstract_methods :update, :valid?
26
+ abstract_methods :valid?
27
27
 
28
28
  # @return [EacRubyUtils::Envs::LocalEnv]
29
29
  def env
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.59.0'
4
+ VERSION = '0.61.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.59.0
4
+ version: 0.61.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: 2023-01-09 00:00:00.000000000 Z
11
+ date: 2023-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -369,6 +369,7 @@ files:
369
369
  - lib/avm/rspec/setup.rb
370
370
  - lib/avm/rspec/setup/launcher.rb
371
371
  - lib/avm/rspec/setup/source_generator.rb
372
+ - lib/avm/rspec/shared_examples/avm_file_format_file_resource_name.rb
372
373
  - lib/avm/rspec/shared_examples/avm_file_formats_with_fixtures.rb
373
374
  - lib/avm/rspec/shared_examples/avm_source_generated.rb
374
375
  - lib/avm/rspec/shared_examples/entries_values.rb
@@ -378,7 +379,6 @@ files:
378
379
  - lib/avm/scms.rb
379
380
  - lib/avm/scms/auto_commit.rb
380
381
  - lib/avm/scms/auto_commit/file_resource_name.rb
381
- - lib/avm/scms/auto_commit/file_resource_name/ruby.rb
382
382
  - lib/avm/scms/auto_commit/for_file.rb
383
383
  - lib/avm/scms/auto_commit/rules.rb
384
384
  - lib/avm/scms/auto_commit/rules/base.rb
@@ -396,6 +396,7 @@ files:
396
396
  - lib/avm/scms/inflector.rb
397
397
  - lib/avm/scms/interval.rb
398
398
  - lib/avm/scms/null.rb
399
+ - lib/avm/scms/null/commit.rb
399
400
  - lib/avm/self/docker_image.rb
400
401
  - lib/avm/self/instance.rb
401
402
  - lib/avm/self/instance/entry_keys.rb
@@ -410,11 +411,15 @@ files:
410
411
  - lib/avm/sources/base/configuration.rb
411
412
  - lib/avm/sources/base/instance.rb
412
413
  - lib/avm/sources/base/locale.rb
414
+ - lib/avm/sources/base/organizational.rb
413
415
  - lib/avm/sources/base/parent.rb
414
416
  - lib/avm/sources/base/stereotype.rb
415
417
  - lib/avm/sources/base/subs.rb
416
418
  - lib/avm/sources/base/subs_paths.rb
417
419
  - lib/avm/sources/base/testing.rb
420
+ - lib/avm/sources/base/update.rb
421
+ - lib/avm/sources/base/update_sub.rb
422
+ - lib/avm/sources/base/version_bump.rb
418
423
  - lib/avm/sources/configuration.rb
419
424
  - lib/avm/sources/configuration/rubocop.rb
420
425
  - lib/avm/sources/runner.rb
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
-
5
- module Avm
6
- module Scms
7
- module AutoCommit
8
- class FileResourceName
9
- module Ruby
10
- RUBY_CLASS_NAME_PATTERNS = [%r{lib/((?!.*/lib/).+)\.rb\z},
11
- %r{app/[^/]+/(.+)\.rb\z}].freeze
12
-
13
- def ruby_class_name
14
- RUBY_CLASS_NAME_PATTERNS.each do |pattern|
15
- pattern.if_match(relative_path.to_path, false) { |m| return m[1].camelize }
16
- end
17
- nil
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end