avm-tools 0.66.0 → 0.67.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: 5fadfbad4ae6f17cae7e5137761710e454d858b08f56b0f666956d7f84c9787b
4
- data.tar.gz: 30bceb50691d6c31bd34980c0985f4a689d16075f01ffba2495441d67913e312
3
+ metadata.gz: 916ea6c3a654cc81c07739fffab5013f51cf9e83a7cf8b1163abef48c6fa7ea8
4
+ data.tar.gz: 7393ff7addec4974fccb0b95b1b6bc5e625e05decc8e695696a1511f4d40c472
5
5
  SHA512:
6
- metadata.gz: 5c88f25a0c0a7ae293d3c7b40f8708cfcdbfe92ace54a85c0b028751b75a044aa0c9ad437d16b3d47e0895bee0338119c6ea18cbf1328124dab7189f28852353
7
- data.tar.gz: eab8e705b2d927f0d196117592a5273ce01f3f55e67e2074691500e44164eed3df86e50e69ece788f77c01fc4b06f39f3aeb670f389ab992c7d539ebc1206eca
6
+ metadata.gz: 70c1fa8e342208bfd2af99796da13e6cad4d86bb1e28f15b92212c5255fbb5de56dbd88a70ac89c84106a82dac44c1429c3bbf1524932034ef797bc690e4c7b3
7
+ data.tar.gz: 2b20f95259f5603547d3484d5771babb52eeaa43be785b0afe16460ac0bac584d8143ec70df2f53e6e567fdd99ad19498375a78eccb7f876c7ad445b44496f83
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/patches/eac_ruby_gems_utils/gem'
4
+ require 'i18n'
5
+
6
+ module Avm
7
+ module Instances
8
+ class Configuration < ::EacRubyUtils::Configs
9
+ LOCALE_KEY = :locale
10
+
11
+ def locale
12
+ read_entry(LOCALE_KEY) || ::I18n.default_locale
13
+ end
14
+ end
15
+ end
16
+ end
@@ -4,6 +4,7 @@ require 'avm/instances/configuration'
4
4
  require 'eac_launcher/paths/real'
5
5
  require 'eac_ruby_utils/core_ext'
6
6
  require 'avm/projects/stereotypes'
7
+ require 'i18n'
7
8
 
8
9
  module Avm
9
10
  module LocalProjects
@@ -16,12 +17,20 @@ module Avm
16
17
 
17
18
  delegate :to_s, to: :path
18
19
 
20
+ def locale
21
+ configuration.if_present(&:locale) || ::I18n.default_locale
22
+ end
23
+
19
24
  # Backward compatibility with [EacLauncher::Paths::Logical].
20
25
  # @return [EacLauncher::Paths::Real].
21
26
  def real
22
27
  ::EacLauncher::Paths::Real.new(path.to_path)
23
28
  end
24
29
 
30
+ def run_job(job, job_args = [])
31
+ stereotypes.each { |stereotype| run_stereotype_job(stereotype, job, job_args) }
32
+ end
33
+
25
34
  private
26
35
 
27
36
  # @return [Avm::Instances::Configuration]
@@ -29,6 +38,16 @@ module Avm
29
38
  ::Avm::Instances::Configuration.find_in_path(path)
30
39
  end
31
40
 
41
+ def run_stereotype_job(stereotype, job, job_args)
42
+ job_class_method = "#{job}_class"
43
+ if stereotype.send(job_class_method).present?
44
+ puts stereotype.label + ": #{job} class found. Running..."
45
+ stereotype.send(job_class_method).new(self, *job_args).run
46
+ else
47
+ puts stereotype.label + ": #{job} class not found"
48
+ end
49
+ end
50
+
32
51
  def stereotypes_uncached
33
52
  ::Avm::Projects::Stereotypes.list.select { |s| s.match?(self) }
34
53
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/self'
4
+ require 'i18n'
5
+
6
+ module Avm
7
+ module Patches
8
+ module I18n
9
+ class << self
10
+ def setup_i18n
11
+ ::I18n.load_path += locale_files_paths.map(&:to_path)
12
+ end
13
+
14
+ def locale_files_paths
15
+ ::Avm::Self.root.join('locale').glob('*.yml')
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ ::Avm::Patches::I18n.setup_i18n
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/patches/i18n'
4
+
5
+ class Object
6
+ def translate(entry_suffix, values = {})
7
+ ::I18n.translate(translate_entry_full(entry_suffix), values)
8
+ end
9
+
10
+ def translate_entry_full(entry_suffix)
11
+ "#{translate_entry_self_prefix}.#{entry_suffix}"
12
+ end
13
+
14
+ def translate_entry_self_prefix
15
+ self.class.name.underscore.gsub('/', '.')
16
+ end
17
+ end
@@ -37,6 +37,7 @@ module Avm
37
37
  local_project_mixin: ::Module,
38
38
  publish: ::Class,
39
39
  update: ::Class,
40
+ version_bump: ::Class,
40
41
  warp: ::Class
41
42
  }.each do |name, is_a|
42
43
  define_method "#{name}_#{is_a.name.underscore}" do
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'avm/patches/eac_ruby_gems_utils/gem'
4
+ require 'avm/version'
4
5
  require 'eac_ruby_utils/core_ext'
5
6
 
6
7
  module Avm
@@ -12,6 +13,14 @@ module Avm
12
13
  def ruby_gem
13
14
  @ruby_gem ||= ::EacRubyGemsUtils::Gem.new(path)
14
15
  end
16
+
17
+ def version
18
+ ruby_gem.version.if_present { |v| ::Avm::Version.new(v) }
19
+ end
20
+
21
+ def version=(value)
22
+ ruby_gem.version_file.value = value
23
+ end
15
24
  end
16
25
  end
17
26
  end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/patches/object/i18n'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Projects
8
+ module Stereotypes
9
+ class RubyGem
10
+ class VersionBump
11
+ enable_console_speaker
12
+ common_constructor :instance, :target_version
13
+
14
+ def run
15
+ git_checkout
16
+ change_version
17
+ bundle_run
18
+ git_commit
19
+ end
20
+
21
+ private
22
+
23
+ def bundle_run
24
+ infom 'Running "bundle install"...'
25
+ instance.ruby_gem.bundle('install').execute!
26
+ end
27
+
28
+ def change_version
29
+ infom 'Setting project version...'
30
+ instance.version = target_version
31
+ end
32
+
33
+ def git_checkout
34
+ return unless instance.respond_to?(:git_repo)
35
+
36
+ infom "Checkouting #{changing_files.map(&:to_path).join(', ')}..."
37
+ instance.git_repo.command('checkout', '--',
38
+ *changing_files.map(&:to_path)).execute!
39
+ end
40
+
41
+ def git_commit
42
+ return unless instance.respond_to?(:git_repo)
43
+
44
+ infom "Commiting #{changing_files.map(&:to_path).join(', ')}..."
45
+ instance.git_repo.command('commit', '-m', git_commit_message, '--',
46
+ *changing_files.map(&:to_path)).execute!
47
+ end
48
+
49
+ def git_commit_message
50
+ ::I18n.default_locale = instance.locale
51
+ translate(__method__, version: target_version)
52
+ end
53
+
54
+ def changing_files
55
+ [instance.ruby_gem.gemfile_lock_path, instance.ruby_gem.version_file_path]
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/local_projects/jobs/update'
4
3
  require 'eac_ruby_utils/console/docopt_runner'
5
4
  require 'eac_ruby_utils/core_ext'
6
5
 
@@ -17,7 +16,7 @@ module Avm
17
16
 
18
17
  def run
19
18
  infov 'Path', context(:instance).path
20
- ::Avm::LocalProjects::Jobs::Update.new(context(:instance)).run
19
+ context(:instance).run_job(:update)
21
20
  end
22
21
  end
23
22
  end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/version'
4
+ require 'eac_ruby_utils/console/docopt_runner'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module Avm
8
+ module Tools
9
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
10
+ class LocalProject < ::EacRubyUtils::Console::DocoptRunner
11
+ class VersionBump < ::EacRubyUtils::Console::DocoptRunner
12
+ include ::EacCli::DefaultRunner
13
+
14
+ runner_definition do
15
+ desc 'Bump version of a local project.'
16
+ arg_opt '-n', '--new', 'Set new version.'
17
+ arg_opt '-s', '--segment', 'Increment de <segment>-th segment (Left-most is 0)'
18
+ bool_opt '-M', '--major', 'Same as --segment=0.'
19
+ bool_opt '-m', '--minor', 'Same as --segment=1.'
20
+ bool_opt '-p', '--patch', 'Same as --segment=2.'
21
+ bool_opt '-y', '--yes', 'Bump without confirmation.'
22
+ end
23
+
24
+ def run
25
+ start_banner
26
+ version_changed? ? run_version_changed : run_version_unchanged
27
+ end
28
+
29
+ def run_version_changed
30
+ infom 'Version changed'
31
+ if confirm?
32
+ context(:instance).run_job(:version_bump, target_version)
33
+ success 'Bumped'
34
+ else
35
+ fatal_error 'Bump unconfirmed'
36
+ end
37
+ end
38
+
39
+ def run_version_unchanged
40
+ success 'Version unchanged'
41
+ end
42
+
43
+ def start_banner
44
+ context(:instance_banner)
45
+ infov 'Current version', current_version.if_present('-')
46
+ infov 'Target version', target_version.if_present('-')
47
+ end
48
+
49
+ def confirm?
50
+ options.fetch('--yes') || request_input('Confirm version bump?', bool: true)
51
+ end
52
+
53
+ def current_version_uncached
54
+ context(:instance).if_respond('version')
55
+ end
56
+
57
+ def target_version_uncached
58
+ r = current_version
59
+ %w[new segment major minor patch].each do |option|
60
+ option_value = options.fetch("--#{option}")
61
+ next if option_value.blank?
62
+
63
+ r = send("target_version_from_#{option}", r, option_value)
64
+ end
65
+ r
66
+ end
67
+
68
+ def target_version_from_new(_current, option_value)
69
+ ::Avm::Version.new(option_value)
70
+ end
71
+
72
+ def target_version_from_segment(current, option_value)
73
+ current.increment_segment(option_value.to_i)
74
+ end
75
+
76
+ %w[major minor patch].each_with_index do |segment, segment_index|
77
+ define_method "target_version_from_#{segment}" do |current, _option_value|
78
+ target_version_from_segment(current, segment_index)
79
+ end
80
+ end
81
+
82
+ def version_changed?
83
+ target_version != current_version
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Tools
5
- VERSION = '0.66.0'
5
+ VERSION = '0.67.0'
6
6
  end
7
7
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ # A sequence of segments of integer versions (Ex.: 2, 1.0.1, 3.0.0.0.0).
5
+ class Version
6
+ include ::Comparable
7
+
8
+ SEGMENT_SEPARATOR = '.'
9
+
10
+ class << self
11
+ def segments_from_mixed(segments)
12
+ (segments.is_a?(::Enumerable) ? segments.to_a : segments.to_s.split(SEGMENT_SEPARATOR))
13
+ .map(&:to_i)
14
+ end
15
+ end
16
+
17
+ attr_reader :segments
18
+
19
+ def initialize(segments)
20
+ @segments = self.class.segments_from_mixed(segments).freeze
21
+ end
22
+
23
+ delegate :[], to: :segments
24
+
25
+ def <=>(other)
26
+ segments <=> other.segments
27
+ end
28
+
29
+ def to_s
30
+ segments.join(SEGMENT_SEPARATOR)
31
+ end
32
+
33
+ # @return [Avm::Version]
34
+ def increment_segment(segment_index)
35
+ x = [segments.count, segment_index + 1].max.times.map do |index|
36
+ value = index < segments.count ? segments[index] : 0
37
+ next value if index < segment_index
38
+ next value + 1 if index == segment_index
39
+
40
+ 0
41
+ end
42
+ self.class.new x
43
+ end
44
+ end
45
+ end
@@ -54,7 +54,7 @@ module EacRubyGemsUtils
54
54
  end
55
55
 
56
56
  def version
57
- /VERSION\s*=\s*[\'\"]([^\'\"]+)[\'\"]/.if_match(version_file.read) { |m| m[1] }
57
+ version_file.value
58
58
  end
59
59
 
60
60
  private
@@ -76,6 +76,10 @@ module EacRubyGemsUtils
76
76
  end
77
77
 
78
78
  def version_file_uncached
79
+ ::EacRubyGemsUtils::Gem::VersionFile.new(version_file_path)
80
+ end
81
+
82
+ def version_file_path_uncached
79
83
  root.join('lib', *namespace_parts, 'version.rb')
80
84
  end
81
85
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacRubyGemsUtils
6
+ class Gem
7
+ class VersionFile
8
+ common_constructor :path
9
+
10
+ VERSION_LINE_PATTERN = /\A(\s*)VERSION\s*=\s*[\'\"]([^\'\"]+)[\'\"](\s*)\z/.freeze
11
+
12
+ def value
13
+ path.read.each_line do |line|
14
+ VERSION_LINE_PATTERN.if_match(line.rstrip, false) do |m|
15
+ ::Gem::Version.new(m[2])
16
+ end
17
+ end
18
+ end
19
+
20
+ def value=(new_value)
21
+ path.write(new_value_content(new_value))
22
+ end
23
+
24
+ private
25
+
26
+ def new_value_content(new_value)
27
+ path.read.each_line
28
+ .map { |line| new_value_line(line, new_value) }
29
+ .join
30
+ end
31
+
32
+ def new_value_line(line, new_value)
33
+ m = VERSION_LINE_PATTERN.match(line)
34
+ return line unless m
35
+
36
+ "#{m[1]}VERSION = '#{new_value}'#{m[3]}"
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyGemsUtils
4
- VERSION = '0.6.2'
4
+ VERSION = '0.7.0'
5
5
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/object/blank'
4
+
5
+ class Object
6
+ # @return +block.call(self.method_name)+ if +self+ responds to +method_name+, +default_value+
7
+ # otherwise.
8
+ def if_respond(method_name, default_value = nil)
9
+ return default_value unless respond_to?(method_name)
10
+
11
+ value = send(method_name)
12
+
13
+ block_given? ? yield(value) : value
14
+ end
15
+
16
+ # @return +yield+ if +self+ is blank.
17
+ def if_blank
18
+ return yield if blank? && block_given?
19
+
20
+ self
21
+ end
22
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.43.0'
4
+ VERSION = '0.44.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.66.0
4
+ version: 0.67.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
@@ -361,6 +361,7 @@ files:
361
361
  - lib/avm/instances/base/auto_values/web.rb
362
362
  - lib/avm/instances/base/dockerizable.rb
363
363
  - lib/avm/instances/configuration.rb
364
+ - lib/avm/instances/configuration/_locale.rb
364
365
  - lib/avm/instances/configuration/_rubocop.rb
365
366
  - lib/avm/instances/configuration/_tests.rb
366
367
  - lib/avm/instances/entries.rb
@@ -376,9 +377,10 @@ files:
376
377
  - lib/avm/launcher/instances/settings.rb
377
378
  - lib/avm/local_projects.rb
378
379
  - lib/avm/local_projects/instance.rb
379
- - lib/avm/local_projects/jobs/update.rb
380
380
  - lib/avm/patches.rb
381
381
  - lib/avm/patches/eac_ruby_gems_utils/gem.rb
382
+ - lib/avm/patches/i18n.rb
383
+ - lib/avm/patches/object/i18n.rb
382
384
  - lib/avm/patches/object/template.rb
383
385
  - lib/avm/path_string.rb
384
386
  - lib/avm/projects.rb
@@ -400,6 +402,7 @@ files:
400
402
  - lib/avm/projects/stereotypes/ruby_gem/local_project_mixin.rb
401
403
  - lib/avm/projects/stereotypes/ruby_gem/publish.rb
402
404
  - lib/avm/projects/stereotypes/ruby_gem/update.rb
405
+ - lib/avm/projects/stereotypes/ruby_gem/version_bump.rb
403
406
  - lib/avm/rails.rb
404
407
  - lib/avm/rails/runners.rb
405
408
  - lib/avm/rails/runners/bundle.rb
@@ -494,6 +497,7 @@ files:
494
497
  - lib/avm/tools/runner/local_project/ruby/bundler/gemfile_lock.rb
495
498
  - lib/avm/tools/runner/local_project/test.rb
496
499
  - lib/avm/tools/runner/local_project/update.rb
500
+ - lib/avm/tools/runner/local_project/version_bump.rb
497
501
  - lib/avm/tools/runner/ruby.rb
498
502
  - lib/avm/tools/runner/ruby/gems.rb
499
503
  - lib/avm/tools/runner/ruby/gems/generate.rb
@@ -501,6 +505,7 @@ files:
501
505
  - lib/avm/tools/runner/self.rb
502
506
  - lib/avm/tools/runner/self/docker.rb
503
507
  - lib/avm/tools/version.rb
508
+ - lib/avm/version.rb
504
509
  - lib/eac_launcher.rb
505
510
  - lib/eac_launcher/context.rb
506
511
  - lib/eac_launcher/context/instance_discovery.rb
@@ -785,6 +790,7 @@ files:
785
790
  - vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils.rb
786
791
  - vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem.rb
787
792
  - vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem/command.rb
793
+ - vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem/version_file.rb
788
794
  - vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests.rb
789
795
  - vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/base.rb
790
796
  - vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/minitest.rb
@@ -890,6 +896,7 @@ files:
890
896
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object.rb
891
897
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/asserts.rb
892
898
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
899
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb
893
900
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/template.rb
894
901
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/to_pathname.rb
895
902
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname.rb
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
-
5
- module Avm
6
- module LocalProjects
7
- module Jobs
8
- class Update
9
- enable_console_speaker
10
- common_constructor :instance
11
-
12
- def run
13
- instance.stereotypes.each { |stereotype| run_stereotype(stereotype) }
14
- end
15
-
16
- private
17
-
18
- def run_stereotype(stereotype)
19
- if stereotype.update_class.present?
20
- puts stereotype.label + ': update class found. Running...'
21
- stereotype.update_class.new(instance).run
22
- else
23
- puts stereotype.label + ': update class not found'
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end