avm 0.58.0 → 0.60.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: a50b6491d183f2df1d7423338b915f2017ec2bf147e6857806c27cdde72ef10d
4
- data.tar.gz: 225020d14af638e08b723a00482794790715165b7cbe092e0833e301ba182993
3
+ metadata.gz: 8ee7bf9c423e00a5bbd0e070ab0f1a191f338e80c794fde0609a3463c7307d78
4
+ data.tar.gz: cdb1a486aadcb408fee1123c133f54c5d46fa912be903f49ed547166027b62a2
5
5
  SHA512:
6
- metadata.gz: e006a7a7a9be79a45abed6317db5de8c6097bd1f5269ec444dc43ad49852713e892c10685e1043f3eb93cfb40a0207739f025c16a758c47a3c3546a48014cc2e
7
- data.tar.gz: 28d138623589418cb34db4ba74d7f0e1b1ecf87695ab5e49e2c62c0420c5631e2b09525952815d1a0b6c837367b1b4ce9123f1d42833ab08f1822aec5a5e2ba2
6
+ metadata.gz: d1a37030086636976394fe3392a2681c4065cb8dbabd32fc1f702193b581372372519ef099b254c7c126f3818cff4715dc1597f2ecab1c65a9953044a20362a0
7
+ data.tar.gz: 2a72c35e69480aabe07bc71a00ec8cfaf30854ced09da08b423f88c9229f59e42275a902d9797f12a23ec5305c4893803770425b439035a96e70d3f45be30060
@@ -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
@@ -0,0 +1,39 @@
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
+ require_sub __FILE__, include_modules: true
10
+ enable_simple_cache
11
+ common_constructor :source_root, :path do
12
+ self.source_root = source_root.to_pathname
13
+ self.path = path.to_pathname
14
+ end
15
+
16
+ def class_name
17
+ file_format.file_resource_name(path)
18
+ end
19
+
20
+ def commit_message
21
+ r = class_name
22
+ r += ': remove' unless path.file?
23
+ r + '.'
24
+ end
25
+
26
+ def relative_path
27
+ path.expand_path.relative_path_from(source_root.expand_path)
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
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/scms/commit_info'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Scms
8
+ module AutoCommit
9
+ class ForFile
10
+ enable_speaker
11
+ enable_simple_cache
12
+ enable_listable
13
+
14
+ common_constructor :scm, :path, :rules do
15
+ self.path = path.to_pathname.expand_path(scm.path)
16
+ end
17
+
18
+ COMMITS_SEARCH_INTERVAL = 'origin/master..HEAD'
19
+
20
+ def scm_relative_path
21
+ path.to_pathname.relative_path_from(scm.path)
22
+ end
23
+
24
+ def run
25
+ start_banner
26
+ run_commit || warn("No rule returned commit information for \"#{path}\"")
27
+ end
28
+
29
+ private
30
+
31
+ def commit_info_uncached
32
+ rules.lazy.map { |rule| rule.with_file(self).commit_info }.find(&:present?)
33
+ .if_present { |v| v.path(path) }
34
+ end
35
+
36
+ def start_banner
37
+ infov 'Path', path
38
+ infov ' Commits found', commits.count
39
+ end
40
+
41
+ def run_commit
42
+ return false if commit_info.blank?
43
+
44
+ infov ' Commit info', commit_info
45
+ scm.run_commit(commit_info)
46
+ success ' Commited'
47
+ true
48
+ end
49
+
50
+ def commits_uncached
51
+ scm.current_milestone_interval.commits
52
+ .select { |c| c.changed_files.include?(path.relative_path_from(scm.path)) }
53
+ .reject(&:fixup?).each_with_index
54
+ .map { |commit, index| CommitDelegator.new(commit, index) }
55
+ end
56
+
57
+ class CommitDelegator < ::SimpleDelegator
58
+ attr_reader :index
59
+
60
+ def initialize(commit, index)
61
+ super(commit)
62
+ @index = index
63
+ end
64
+
65
+ def position
66
+ index + 1
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/scms/commit_info'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Scms
8
+ module AutoCommit
9
+ module Rules
10
+ class Base
11
+ class << self
12
+ def keys
13
+ [long_key, short_key]
14
+ end
15
+
16
+ def long_key
17
+ name.demodulize.variableize
18
+ end
19
+
20
+ def short_key
21
+ long_key[0, 1]
22
+ end
23
+ end
24
+
25
+ def with_file(file)
26
+ self.class.const_get('WithFile').new(self, file)
27
+ end
28
+
29
+ class WithFile
30
+ common_constructor :rule, :file
31
+
32
+ def new_commit_info
33
+ ::Avm::Scms::CommitInfo.new
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/scms/auto_commit/rules/base'
4
+
5
+ module Avm
6
+ module Scms
7
+ module AutoCommit
8
+ module Rules
9
+ class Last < ::Avm::Scms::AutoCommit::Rules::Base
10
+ class WithFile < ::Avm::Scms::AutoCommit::Rules::Base::WithFile
11
+ def commit_info
12
+ file.commits.last.if_present { |v| new_commit_info.fixup(v) }
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/scms/auto_commit/rules/base'
4
+
5
+ module Avm
6
+ module Scms
7
+ module AutoCommit
8
+ module Rules
9
+ class Manual < ::Avm::Scms::AutoCommit::Rules::Base
10
+ class WithFile < ::Avm::Scms::AutoCommit::Rules::Base::WithFile
11
+ enable_speaker
12
+
13
+ SKIP_OPTION = 's'
14
+
15
+ def commit_info
16
+ return nil unless file.commits.any?
17
+
18
+ commits_banner
19
+ input('Which commit?', list: commits_by_position).if_present do |v|
20
+ new_commit_info.fixup(v)
21
+ end
22
+ end
23
+
24
+ def commits_banner
25
+ file.commits.each_with_index do |commit, _index|
26
+ infov " #{commit.position}", commit
27
+ end
28
+ infov " #{SKIP_OPTION}", 'skip'
29
+ end
30
+
31
+ def commits_by_position
32
+ (file.commits.map { |commit| [commit.position.to_s, commit] } + [[SKIP_OPTION, nil]])
33
+ .to_h
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/scms/auto_commit/rules/base'
4
+ require 'avm/scms/auto_commit/file_resource_name'
5
+
6
+ module Avm
7
+ module Scms
8
+ module AutoCommit
9
+ module Rules
10
+ class New < ::Avm::Scms::AutoCommit::Rules::Base
11
+ class WithFile < ::Avm::Scms::AutoCommit::Rules::Base::WithFile
12
+ def auto_commit_path
13
+ ::Avm::Scms::AutoCommit::FileResourceName.new(file.scm.path, file.path)
14
+ end
15
+
16
+ def commit_info
17
+ new_commit_info.message(auto_commit_path.commit_message)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/scms/auto_commit/rules/base'
4
+
5
+ module Avm
6
+ module Scms
7
+ module AutoCommit
8
+ module Rules
9
+ class Nth < ::Avm::Scms::AutoCommit::Rules::Base
10
+ SHORT_KEY = 't'
11
+
12
+ class << self
13
+ def short_key
14
+ SHORT_KEY
15
+ end
16
+ end
17
+
18
+ common_constructor :number do
19
+ self.number = number.to_i
20
+ end
21
+
22
+ class WithFile < ::Avm::Scms::AutoCommit::Rules::Base::WithFile
23
+ def commit_info
24
+ file.commits(number - 1).if_present { |v| new_commit_info.fixup(v) }
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/scms/auto_commit/rules/base'
4
+
5
+ module Avm
6
+ module Scms
7
+ module AutoCommit
8
+ module Rules
9
+ class Unique < ::Avm::Scms::AutoCommit::Rules::Base
10
+ class WithFile < ::Avm::Scms::AutoCommit::Rules::Base::WithFile
11
+ def commit_info
12
+ return nil unless file.commits.count == 1
13
+
14
+ new_commit_info.fixup(file.commits.first)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ ::EacRubyUtils.require_sub __FILE__
6
+
7
+ module Avm
8
+ module Scms
9
+ module AutoCommit
10
+ module Rules
11
+ RULES_CLASSES = %w[last manual new nth unique]
12
+ .map { |key| ::Avm::Scms::AutoCommit::Rules.const_get(key.camelcase) }
13
+
14
+ class << self
15
+ # @return [Array<Avm::Scms::AutoCommit::Rules>]
16
+ def all
17
+ RULES_CLASSES
18
+ end
19
+
20
+ def parse(string)
21
+ parts = string.split(':')
22
+
23
+ klass = rule_class_by_key(parts.shift)
24
+ klass.new(*parts)
25
+ end
26
+
27
+ def rule_class_by_key(key)
28
+ RULES_CLASSES.find { |klass| klass.keys.include?(key) } ||
29
+ raise("Rule not find with key \"#{key}\" (Available: " +
30
+ RULES_CLASSES.flat_map(&:keys).join(', ') + ')')
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Scms
7
+ module AutoCommit
8
+ require_sub __FILE__
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Scms
7
+ class Base
8
+ module Commits
9
+ # @return [Avm::Scms::Commit,NilClass]
10
+ def commit_if_change(_message = nil)
11
+ raise_abstract_method __method__
12
+ end
13
+
14
+ # @return [Avm::Scms::Commit]
15
+ def head_commit
16
+ raise_abstract_method __method__
17
+ end
18
+
19
+ # @param commit_info [Avm::Scms::CommitInfo]
20
+ # @return [Avm::Scms::Commit]
21
+ def run_commit(_commit_info)
22
+ raise_abstract_method __method__
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Scms
7
+ class Base
8
+ module Milestones
9
+ # @return [Avm::Scms::Interval]
10
+ def current_milestone_interval
11
+ interval(current_milestone_base_commit, head_commit)
12
+ end
13
+
14
+ # @return [Avm::Scms::Commit]
15
+ def current_milestone_base_commit
16
+ raise_abstract_method __method__
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
data/lib/avm/scms/base.rb CHANGED
@@ -6,6 +6,7 @@ require 'eac_ruby_utils/core_ext'
6
6
  module Avm
7
7
  module Scms
8
8
  class Base
9
+ require_sub __FILE__, include_modules: true
9
10
  enable_abstract_methods
10
11
  enable_simple_cache
11
12
  include ::Avm::With::ApplicationStereotype
@@ -14,8 +15,13 @@ module Avm
14
15
  self.path = path.to_pathname
15
16
  end
16
17
 
17
- # @return [Avm::Scms::Commit,NilClass]
18
- def commit_if_change(_message = nil)
18
+ # @return [Avm::Scms::ChangedFile]
19
+ def changed_files
20
+ raise_abstract_method __method__
21
+ end
22
+
23
+ # @return [Avm::Scms::Interval]
24
+ def interval(_from, _to)
19
25
  raise_abstract_method __method__
20
26
  end
21
27
 
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Scms
7
+ class ChangedFile
8
+ enable_abstract_methods
9
+
10
+ # @return [Pathname]
11
+ def absolute_path
12
+ path.expand_path(scm.path)
13
+ end
14
+
15
+ # @return [Pathname]
16
+ def path
17
+ raise_abstract_method __method__
18
+ end
19
+
20
+ # @return [Avm::Scms::Base]
21
+ def scm
22
+ raise_abstract_method __method__
23
+ end
24
+ end
25
+ end
26
+ end
@@ -16,6 +16,11 @@ module Avm
16
16
  raise_abstract_method __method__
17
17
  end
18
18
 
19
+ # @return [Boolean]
20
+ def fixup?
21
+ raise_abstract_method __method__
22
+ end
23
+
19
24
  def id
20
25
  raise_abstract_method __method__
21
26
  end
@@ -46,6 +51,16 @@ module Avm
46
51
  def scm_file?(_path)
47
52
  raise_abstract_method __method__
48
53
  end
54
+
55
+ # @return [String]
56
+ def subject
57
+ raise_abstract_method __method__
58
+ end
59
+
60
+ # @return [String]
61
+ def to_s
62
+ "#{subject} [#{id}]"
63
+ end
49
64
  end
50
65
  end
51
66
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Scms
7
+ class CommitInfo
8
+ enable_immutable
9
+
10
+ immutable_accessor :fixup, :message
11
+ immutable_accessor :path, type: :array
12
+
13
+ def to_s
14
+ self.class.name.demodulize + '[' +
15
+ %w[fixup message].map { |m| [m, send(m)] }.reject { |m| m[1].blank? }
16
+ .map { |m| m.join(': ') }.join(',') + ']'
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Scms
7
+ class Interval
8
+ enable_abstract_methods
9
+
10
+ common_constructor :scm, :from, :to
11
+
12
+ # @return [Array<Avm::Scms::Commit>]
13
+ def commits
14
+ raise_abstract_method __method__
15
+ end
16
+ end
17
+ end
18
+ end
data/lib/avm/scms.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Scms
7
+ require_sub __FILE__
8
+ end
9
+ 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.58.0'
4
+ VERSION = '0.60.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.58.0
4
+ version: 0.60.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-12-24 00:00:00.000000000 Z
11
+ date: 2023-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -106,20 +106,20 @@ dependencies:
106
106
  requirements:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: '0.109'
109
+ version: '0.110'
110
110
  - - ">="
111
111
  - !ruby/object:Gem::Version
112
- version: 0.109.1
112
+ version: 0.110.1
113
113
  type: :runtime
114
114
  prerelease: false
115
115
  version_requirements: !ruby/object:Gem::Requirement
116
116
  requirements:
117
117
  - - "~>"
118
118
  - !ruby/object:Gem::Version
119
- version: '0.109'
119
+ version: '0.110'
120
120
  - - ">="
121
121
  - !ruby/object:Gem::Version
122
- version: 0.109.1
122
+ version: 0.110.1
123
123
  - !ruby/object:Gem::Dependency
124
124
  name: eac_templates
125
125
  requirement: !ruby/object:Gem::Requirement
@@ -369,15 +369,32 @@ 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
375
376
  - lib/avm/rspec/shared_examples/in_avm_registry.rb
376
377
  - lib/avm/rspec/shared_examples/not_in_avm_registry.rb
377
378
  - lib/avm/runners/base.rb
379
+ - lib/avm/scms.rb
380
+ - lib/avm/scms/auto_commit.rb
381
+ - lib/avm/scms/auto_commit/file_resource_name.rb
382
+ - lib/avm/scms/auto_commit/for_file.rb
383
+ - lib/avm/scms/auto_commit/rules.rb
384
+ - lib/avm/scms/auto_commit/rules/base.rb
385
+ - lib/avm/scms/auto_commit/rules/last.rb
386
+ - lib/avm/scms/auto_commit/rules/manual.rb
387
+ - lib/avm/scms/auto_commit/rules/new.rb
388
+ - lib/avm/scms/auto_commit/rules/nth.rb
389
+ - lib/avm/scms/auto_commit/rules/unique.rb
378
390
  - lib/avm/scms/base.rb
391
+ - lib/avm/scms/base/commits.rb
392
+ - lib/avm/scms/base/milestones.rb
393
+ - lib/avm/scms/changed_file.rb
379
394
  - lib/avm/scms/commit.rb
395
+ - lib/avm/scms/commit_info.rb
380
396
  - lib/avm/scms/inflector.rb
397
+ - lib/avm/scms/interval.rb
381
398
  - lib/avm/scms/null.rb
382
399
  - lib/avm/self/docker_image.rb
383
400
  - lib/avm/self/instance.rb