avm-tools 0.78.0 → 0.82.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/data/unit.rb +8 -3
  3. data/lib/avm/eac_rails_base0/apache_host.rb +2 -9
  4. data/lib/avm/eac_rails_base1/apache_host.rb +17 -0
  5. data/lib/avm/eac_rails_base1/runner/code_runner.rb +1 -2
  6. data/lib/avm/eac_rails_base1/runner/rails_server.rb +33 -0
  7. data/lib/avm/eac_redmine_base0/apache_host.rb +10 -0
  8. data/lib/avm/eac_redmine_base0/data_unit.rb +29 -1
  9. data/lib/avm/patches/class/i18n.rb +31 -0
  10. data/lib/avm/patches/object/i18n.rb +2 -10
  11. data/lib/avm/projects/stereotypes/ruby_gem/update.rb +4 -1
  12. data/lib/avm/projects/stereotypes/ruby_gem/version_bump.rb +1 -2
  13. data/lib/avm/tools/runner/git/subrepo/fix.rb +65 -0
  14. data/lib/avm/tools/version.rb +1 -1
  15. data/vendor/eac_cli/eac_cli.gemspec +1 -1
  16. data/vendor/eac_cli/lib/eac_cli/parser.rb +6 -4
  17. data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +4 -0
  18. data/vendor/eac_cli/lib/eac_cli/runner.rb +10 -2
  19. data/vendor/eac_cli/lib/eac_cli/runner/exit.rb +13 -0
  20. data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +15 -0
  21. data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +1 -1
  22. data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
  23. data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +6 -3
  24. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/help_spec.rb +42 -0
  25. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +0 -1
  26. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +2 -50
  27. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/class_setup.rb +52 -0
  28. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb +31 -0
  29. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +4 -6
  30. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/concat.rb +33 -0
  31. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/envvars.rb +24 -0
  32. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb +0 -21
  33. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +7 -1
  34. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  35. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +30 -17
  36. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +12 -1
  37. metadata +13 -4
  38. data/lib/avm/tools/runner/eac_rails_base0/rails_server.rb +0 -36
  39. data/lib/avm/tools/runner/eac_rails_base0/runner.rb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31676da0253c7ec8dc92aee2619723858f021faedb659e4f6128a7552eaad975
4
- data.tar.gz: b6c14df8700750c9e0a39c9b8de6ee78e5864bdbf8ff2c21c7c59f029257437f
3
+ metadata.gz: 810bb2b051e5c63d3eed6093eed8e78c8f76ede7a9ac5adfdaa42f5d08628f93
4
+ data.tar.gz: 2708dd1270ec32a734db517ec82015f9e390f415eb51b23f8cce8b11c3a772c8
5
5
  SHA512:
6
- metadata.gz: 989f01a3eb81d88b99186f3471f7437cdd00d7f6d182a68cb2f1080461f08cbadb84bb30782e8bab731eecd75782cc7728d175920cb28f8544e31f88e435ef02
7
- data.tar.gz: 2b51fd22a6aec3d7955f75c3f4d1c68fc5a60c2c8c2dbc13e25cdaff6396df1ba655e1ef5183ab3081e18f17b642a5cf832f7583e80997c6bfb121c90fd0c0a4
6
+ metadata.gz: 0a97ffc1122511054c5f0629c3c67d90d6df8544cb2cc821bce1fb546c550a8ce1963a1fd34d52c0dbdaf351b931cbd3bdd96f1817888eee5d0182396c3f06d0
7
+ data.tar.gz: 9267154e5c284a1d8d74cb8c7eb144df2a5601eb6d5e4b0f847d0f746bd988147f147a82792951b8a100c11da728a32cdc8b76dd129537dcb49b8ec75ba4bdf1
@@ -12,11 +12,12 @@ module Avm
12
12
  enable_console_speaker
13
13
 
14
14
  %w[dump load].each do |action|
15
+ method_name = "#{action}_command"
15
16
  class_eval <<~CODE, __FILE__, __LINE__ + 1
16
17
  # Should be overrided.
17
18
  # @return [EacRubyUtils::Envs::Command]
18
- def #{action}_command
19
- fail "Abstract method. Override in #{singleton_class}."
19
+ def #{method_name}
20
+ fail "\\"#{method_name}\\" is a abstract method. Override in #{singleton_class}."
20
21
  end
21
22
  CODE
22
23
 
@@ -69,7 +70,7 @@ module Avm
69
70
  def load(data_path)
70
71
  run_callbacks :load do
71
72
  infom "Loading unit \"#{name}\" from \"#{data_path}\"..."
72
- load_command.execute!(input_file: data_path)
73
+ do_load(data_path)
73
74
  end
74
75
  end
75
76
 
@@ -79,6 +80,10 @@ module Avm
79
80
  dump_command.execute!(output_file: data_path)
80
81
  end
81
82
 
83
+ def do_load(data_path)
84
+ load_command.execute!(input_file: data_path)
85
+ end
86
+
82
87
  private
83
88
 
84
89
  def unit_on_directory_path(directory, identifier)
@@ -1,17 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/eac_webapp_base0/apache_host'
3
+ require 'avm/eac_rails_base1/apache_host'
4
4
 
5
5
  module Avm
6
6
  module EacRailsBase0
7
- class ApacheHost < ::Avm::EacWebappBase0::ApacheHost
8
- def document_root
9
- "#{instance.read_entry(::Avm::Instances::EntryKeys::FS_PATH)}/public"
10
- end
11
-
12
- def extra_content
13
- 'PassengerEnabled On'
14
- end
7
+ class ApacheHost < ::Avm::EacRailsBase1::ApacheHost
15
8
  end
16
9
  end
17
10
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_webapp_base0/apache_host'
4
+
5
+ module Avm
6
+ module EacRailsBase1
7
+ class ApacheHost < ::Avm::EacWebappBase0::ApacheHost
8
+ def document_root
9
+ "#{instance.read_entry(::Avm::Instances::EntryKeys::FS_PATH)}/public"
10
+ end
11
+
12
+ def extra_content
13
+ 'PassengerEnabled On'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -8,8 +8,7 @@ module Avm
8
8
  module EacRailsBase1
9
9
  class Runner < ::Avm::EacWebappBase0::Runner
10
10
  class CodeRunner
11
- runner_with ::Avm::EacRailsBase1::RunnerWith::Bundle
12
- runner_definition do
11
+ runner_with :help, ::Avm::EacRailsBase1::RunnerWith::Bundle do
13
12
  desc 'Runs a Ruby code with "rails runner".'
14
13
  pos_arg :code
15
14
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_rails_base1/runner_with/bundle'
4
+ require 'avm/instances/entry_keys'
5
+ require 'eac_cli/core_ext'
6
+ require 'eac_ruby_utils/console/docopt_runner'
7
+ require 'shellwords'
8
+
9
+ module Avm
10
+ module EacRailsBase1
11
+ class Runner < ::Avm::EacWebappBase0::Runner
12
+ class RailsServer
13
+ DEFAULT_RAILS_ENVIRONMENT = 'development'
14
+ runner_with :help, ::Avm::EacRailsBase1::RunnerWith::Bundle do
15
+ desc 'Run the embbeded Rails web server.'
16
+ end
17
+
18
+ def run
19
+ infov 'Environment', rails_environment
20
+ infov 'Bundle args', ::Shellwords.join(bundle_args)
21
+ infov 'Result', bundle_command.system
22
+ end
23
+
24
+ protected
25
+
26
+ def bundle_args
27
+ ['exec', 'rails', 'server', '--port',
28
+ runner_context.call(:instance).read_entry(::Avm::Instances::EntryKeys::WEB_PORT)]
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_rails_base1/apache_host'
4
+
5
+ module Avm
6
+ module EacRedmineBase0
7
+ class ApacheHost < ::Avm::EacRailsBase1::ApacheHost
8
+ end
9
+ end
10
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'avm/data/instance/unit'
4
4
  require 'eac_ruby_utils/core_ext'
5
+ require 'curb'
5
6
  require 'open-uri'
6
7
 
7
8
  module Avm
@@ -17,8 +18,35 @@ module Avm
17
18
  end
18
19
  end
19
20
 
21
+ def do_load(data_path)
22
+ do_load_by_web(data_path) || do_load_by_rake(data_path) || raise('Failed to load')
23
+ end
24
+
25
+ def do_load_by_web(data_path)
26
+ c = Curl::Easy.new(import_url)
27
+ c.multipart_form_post = true
28
+ c.http_post(Curl::PostField.file('redmine_with_git_tableless_load[path]', data_path))
29
+ c.perform
30
+ true
31
+ rescue Curl::Err::ConnectionFailedError
32
+ false
33
+ end
34
+
35
+ def do_load_by_rake(data_path)
36
+ instance.bundle('exec', 'rake', "redmine_with_git:load:all[#{data_path}]").system
37
+ true
38
+ end
39
+
20
40
  def export_url
21
- uri = ::Addressable::URI.parse(instance.read_entry('web.url')) + '/backup/export'
41
+ url('/backup/export')
42
+ end
43
+
44
+ def import_url
45
+ url('/backup/import.json')
46
+ end
47
+
48
+ def url(path)
49
+ uri = ::Addressable::URI.parse(instance.read_entry('web.url')) + path
22
50
  uri.query_values = { key: instance.read_entry('admin.api_key') }
23
51
  uri.to_s
24
52
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/patches/i18n'
4
+
5
+ class Class
6
+ TRANSLATE_LOCALE_KEY = :__locale
7
+
8
+ def translate(entry_suffix, values = {})
9
+ on_i18n_locale(values.delete(TRANSLATE_LOCALE_KEY)) do
10
+ ::I18n.translate(translate_entry_full(entry_suffix), values)
11
+ end
12
+ end
13
+
14
+ def translate_entry_full(entry_suffix)
15
+ "#{translate_entry_self_prefix}.#{entry_suffix}"
16
+ end
17
+
18
+ def translate_entry_self_prefix
19
+ name.underscore.gsub('/', '.')
20
+ end
21
+
22
+ def on_i18n_locale(locale)
23
+ old_locale = ::I18n.locale
24
+ begin
25
+ ::I18n.locale = locale
26
+ yield
27
+ ensure
28
+ ::I18n.locale = old_locale
29
+ end
30
+ end
31
+ end
@@ -1,17 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/patches/i18n'
3
+ require 'avm/patches/class/i18n'
4
4
 
5
5
  class Object
6
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('/', '.')
7
+ self.class.translate(entry_suffix, values)
16
8
  end
17
9
  end
@@ -1,12 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
+ require 'avm/patches/class/i18n'
4
5
 
5
6
  module Avm
6
7
  module Projects
7
8
  module Stereotypes
8
9
  class RubyGem
9
10
  class Update
11
+ TRANSLATE_CLASS = self
12
+
10
13
  enable_console_speaker
11
14
  common_constructor :instance
12
15
 
@@ -46,7 +49,7 @@ module Avm
46
49
  end
47
50
 
48
51
  def gemfile_lock_commit_message
49
- 'Todas as gems: atualiza.'
52
+ TRANSLATE_CLASS.translate(__method__, __locale: instance.locale)
50
53
  end
51
54
 
52
55
  def gemfile_lock_changed?
@@ -47,8 +47,7 @@ module Avm
47
47
  end
48
48
 
49
49
  def git_commit_message
50
- ::I18n.default_locale = instance.locale
51
- translate(__method__, version: target_version)
50
+ translate(__method__, version: target_version, __locale: instance.locale)
52
51
  end
53
52
 
54
53
  def changing_files
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/core_ext'
4
+ require 'eac_git/local'
5
+ require 'eac_ruby_utils/console/docopt_runner'
6
+
7
+ module Avm
8
+ module Tools
9
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
10
+ class Git < ::EacRubyUtils::Console::DocoptRunner
11
+ class Subrepo < ::EacRubyUtils::Console::DocoptRunner
12
+ class Fix
13
+ runner_with :help do
14
+ desc 'Fix git-subrepos\' parent property.'
15
+ end
16
+
17
+ def run
18
+ loop do
19
+ break if fix
20
+
21
+ amend_each
22
+ rebase_fixup
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def amend_each
29
+ infov 'Dirty files', local_repos.dirty_files.count
30
+ local_repos.dirty_files.each do |file|
31
+ infov ' * Ammending', file.path
32
+ ::Avm::Git::FileAutoFixup.new(runner_context.call(:git), file.path).run
33
+ end
34
+ end
35
+
36
+ def fix
37
+ infom 'Checking/fixing...'
38
+ c = new_check(true)
39
+ c.show_result
40
+ !c.result.error?
41
+ end
42
+
43
+ def new_check(fix_parent = false)
44
+ r = ::Avm::Git::SubrepoChecks.new(local_repos).add_all_subrepos
45
+ r.fix_parent = fix_parent
46
+ r
47
+ end
48
+
49
+ def local_repos_uncached
50
+ ::EacGit::Local.new(runner_context.call(:git))
51
+ end
52
+
53
+ def rebase_fixup
54
+ local_repos.command('rebase', '-i', 'origin/master', '--autosquash').envvar(
55
+ 'GIT_SEQUENCE_EDITOR', 'true'
56
+ ).or(
57
+ local_repos.command('rebase', '--continue').envvar('GIT_SEQUENCE_EDITOR', 'true')
58
+ ).system!
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Tools
5
- VERSION = '0.78.0'
5
+ VERSION = '0.82.1'
6
6
  end
7
7
  end
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = Dir['{lib}/**/*', 'Gemfile']
14
14
 
15
- s.add_dependency 'eac_ruby_utils', '~> 0.50'
15
+ s.add_dependency 'eac_ruby_utils', '~> 0.55'
16
16
 
17
17
  s.add_development_dependency 'eac_ruby_gem_support', '~> 0.1', '>= 0.1.2'
18
18
  end
@@ -12,12 +12,14 @@ module EacCli
12
12
 
13
13
  def parsed_uncached
14
14
  raise 'Definition has no alternatives' if alternatives.empty?
15
+ raise first_error unless alternatives.select(&:success?).any?
15
16
 
16
- alternatives.each do |alt_parser|
17
- return alt_parser.parsed unless alt_parser.error?
18
- end
17
+ alternatives_parsed(true).merge(alternatives_parsed(false))
18
+ end
19
19
 
20
- raise first_error
20
+ def alternatives_parsed(error)
21
+ alternatives.select { |a| error == a.error? }.map(&:parsed).reverse
22
+ .inject(::EacRubyUtils::Struct.new) { |a, e| a.merge(e) }
21
23
  end
22
24
 
23
25
  def alternatives_uncached
@@ -22,6 +22,10 @@ module EacCli
22
22
  error.present?
23
23
  end
24
24
 
25
+ def success?
26
+ !error?
27
+ end
28
+
25
29
  def parsed
26
30
  @parsed ||= collector.to_data.freeze
27
31
  end
@@ -44,6 +44,8 @@ module EacCli
44
44
  extend AfterClassMethods
45
45
  include InstanceMethods
46
46
  ::EacCli::Docopt::RunnerExtension.check(self)
47
+ include ActiveSupport::Callbacks
48
+ define_callbacks :run
47
49
  end
48
50
 
49
51
  module AfterClassMethods
@@ -55,8 +57,7 @@ module EacCli
55
57
 
56
58
  def run(*runner_context_args)
57
59
  r = create(*runner_context_args)
58
- r.parsed
59
- r.run
60
+ r.run_run
60
61
  r
61
62
  end
62
63
 
@@ -72,6 +73,13 @@ module EacCli
72
73
  end
73
74
 
74
75
  module InstanceMethods
76
+ def run_run
77
+ parsed
78
+ run_callbacks(:run) { run }
79
+ rescue ::EacCli::Runner::Exit # rubocop:disable Lint/SuppressedException
80
+ # Do nothing
81
+ end
82
+
75
83
  def runner_context
76
84
  return @runner_context if @runner_context
77
85
 
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ module Runner
5
+ class Exit < ::StandardError
6
+ attr_reader :status
7
+
8
+ def initialize(status = true)
9
+ @status = status
10
+ end
11
+ end
12
+ end
13
+ end
@@ -13,6 +13,21 @@ module EacCli
13
13
  options_argument false
14
14
  bool_opt '-h', '--help', 'Show help.', usage: true
15
15
  end
16
+
17
+ set_callback :run, :before do
18
+ help_run
19
+ end
20
+ end
21
+
22
+ def help_run
23
+ return unless parsed.help?
24
+
25
+ puts help_text
26
+ raise ::EacCli::Runner::Exit
27
+ end
28
+
29
+ def help_text
30
+ ::EacCli::Docopt::DocBuilder.new(self.class.runner_definition).to_s
16
31
  end
17
32
  end
18
33
  end
@@ -44,7 +44,7 @@ module EacCli
44
44
 
45
45
  def run_with_subcommand
46
46
  if subcommand_name
47
- subcommand_runner.run
47
+ subcommand_runner.run_run
48
48
  else
49
49
  run_without_subcommand
50
50
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacCli
4
- VERSION = '0.12.2'
4
+ VERSION = '0.12.3'
5
5
  end
@@ -28,7 +28,10 @@ RSpec.describe ::EacCli::Runner do
28
28
 
29
29
  context 'when all args are supplied' do
30
30
  let(:argv) { %w[--opt1 aaa --opt2 bbb ccc ddd] }
31
- let(:parsed_expected) { { opt1: 'aaa', opt2: true, pos1: 'bbb', pos2: %w[ccc ddd] } }
31
+ let(:parsed_expected) do
32
+ { opt1: 'aaa', opt2: true, opt3: false, pos1: 'bbb',
33
+ pos2: %w[ccc ddd] }
34
+ end
32
35
 
33
36
  it { expect(parsed_actual).to eq(parsed_expected) }
34
37
  it { expect(instance.parsed.opt1).to eq('aaa') }
@@ -39,7 +42,7 @@ RSpec.describe ::EacCli::Runner do
39
42
 
40
43
  context 'when only required args are supplied' do
41
44
  let(:argv) { %w[bbb] }
42
- let(:parsed_expected) { { opt1: nil, opt2: false, pos1: 'bbb', pos2: [] } }
45
+ let(:parsed_expected) { { opt1: nil, opt2: false, opt3: false, pos1: 'bbb', pos2: [] } }
43
46
 
44
47
  it { expect(parsed_actual).to eq(parsed_expected) }
45
48
  it { expect(instance.parsed.opt1).to be_nil }
@@ -58,7 +61,7 @@ RSpec.describe ::EacCli::Runner do
58
61
 
59
62
  context 'when alternative args are supplied' do
60
63
  let(:argv) { %w[--opt3] }
61
- let(:parsed_expected) { { opt3: true } }
64
+ let(:parsed_expected) { { opt1: nil, opt2: false, opt3: true, pos1: nil, pos2: [] } }
62
65
 
63
66
  it { expect(parsed_actual).to eq(parsed_expected) }
64
67
  it { expect(instance.parsed.opt3?).to eq(true) }
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner_with/help'
4
+ require 'eac_ruby_utils/fs/temp'
5
+
6
+ RSpec.describe ::EacCli::RunnerWith::Help do
7
+ let(:runner) do
8
+ the_module = described_class
9
+ Class.new do
10
+ include the_module
11
+
12
+ runner_definition do
13
+ desc 'A stub runner.'
14
+ pos_arg :a_argument
15
+ end
16
+
17
+ def run
18
+ puts 'Runner run'
19
+ end
20
+ end
21
+ end
22
+
23
+ let(:runner_argv) { ['--help'] }
24
+ let(:instance) { runner.create(argv: runner_argv) }
25
+ let(:expected_output) do
26
+ <<~OUTPUT
27
+ A stub runner.
28
+
29
+ Usage:
30
+ __PROGRAM__ [options] <a_argument>
31
+ __PROGRAM__ --help
32
+
33
+ Options:
34
+ -h --help Show help.
35
+
36
+ OUTPUT
37
+ end
38
+
39
+ it 'show help text' do
40
+ expect { instance.run_run }.to output(expected_output).to_stdout_from_any_process
41
+ end
42
+ end
@@ -8,7 +8,6 @@ RSpec.describe ::EacCli::RunnerWith::Subcommands do
8
8
  the_module = described_class
9
9
  the_child = child_runner
10
10
  Class.new do
11
- include ::EacCli::Runner
12
11
  include the_module
13
12
  const_set('ChildCmd', the_child)
14
13
 
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/concern'
4
- require 'eac_ruby_utils/simple_cache'
5
- require 'eac_ruby_utils/patches/object/if_present'
3
+ require 'eac_ruby_utils/common_concern/module_setup'
6
4
 
7
5
  module EacRubyUtils
8
6
  class CommonConcern
@@ -16,53 +14,7 @@ module EacRubyUtils
16
14
  end
17
15
 
18
16
  def setup(a_module)
19
- Setup.new(self, a_module).run
20
- end
21
-
22
- class Setup
23
- include ::EacRubyUtils::SimpleCache
24
- attr_reader :a_module, :common_concern
25
-
26
- def initialize(common_concern, a_module)
27
- @common_concern = common_concern
28
- @a_module = a_module
29
- end
30
-
31
- def run
32
- setup = self
33
- a_module.extend(::ActiveSupport::Concern)
34
- a_module.included do
35
- %w[class_methods instance_methods after_callback].each do |suffix|
36
- setup.send("setup_#{suffix}", self)
37
- end
38
- end
39
- end
40
-
41
- def setup_class_methods(base)
42
- class_methods_module.if_present { |v| base.extend v }
43
- end
44
-
45
- def setup_instance_methods(base)
46
- instance_methods_module.if_present { |v| base.include v }
47
- end
48
-
49
- def setup_after_callback(base)
50
- common_concern.after_callback.if_present do |v|
51
- base.instance_eval(&v)
52
- end
53
- end
54
-
55
- def class_methods_module_uncached
56
- a_module.const_get(CLASS_METHODS_MODULE_NAME)
57
- rescue NameError
58
- nil
59
- end
60
-
61
- def instance_methods_module_uncached
62
- a_module.const_get(INSTANCE_METHODS_MODULE_NAME)
63
- rescue NameError
64
- nil
65
- end
17
+ ::EacRubyUtils::CommonConcern::ModuleSetup.new(self, a_module).run
66
18
  end
67
19
  end
68
20
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/concern'
4
+ require 'eac_ruby_utils/simple_cache'
5
+ require 'eac_ruby_utils/patches/object/if_present'
6
+
7
+ module EacRubyUtils
8
+ class CommonConcern
9
+ class ClassSetup
10
+ include ::EacRubyUtils::SimpleCache
11
+ attr_reader :a_class, :module_setup, :include_method
12
+
13
+ def initialize(module_setup, a_class, include_method)
14
+ @module_setup = module_setup
15
+ @a_class = a_class
16
+ @include_method = include_method
17
+ end
18
+
19
+ def run
20
+ %w[class_methods instance_methods after_callback].each do |suffix|
21
+ send("setup_#{suffix}")
22
+ end
23
+ end
24
+
25
+ def setup_class_methods
26
+ class_methods_module.if_present { |v| a_class.extend v }
27
+ end
28
+
29
+ def setup_instance_methods
30
+ instance_methods_module.if_present { |v| a_class.send(include_method, v) }
31
+ end
32
+
33
+ def setup_after_callback
34
+ module_setup.common_concern.after_callback.if_present do |v|
35
+ a_class.instance_eval(&v)
36
+ end
37
+ end
38
+
39
+ def class_methods_module_uncached
40
+ module_setup.a_module.const_get(CLASS_METHODS_MODULE_NAME)
41
+ rescue NameError
42
+ nil
43
+ end
44
+
45
+ def instance_methods_module_uncached
46
+ module_setup.a_module.const_get(INSTANCE_METHODS_MODULE_NAME)
47
+ rescue NameError
48
+ nil
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/concern'
4
+ require 'eac_ruby_utils/common_concern/class_setup'
5
+ require 'eac_ruby_utils/simple_cache'
6
+ require 'eac_ruby_utils/patches/object/if_present'
7
+
8
+ module EacRubyUtils
9
+ class CommonConcern
10
+ class ModuleSetup
11
+ include ::EacRubyUtils::SimpleCache
12
+ attr_reader :a_module, :common_concern
13
+
14
+ def initialize(common_concern, a_module)
15
+ @common_concern = common_concern
16
+ @a_module = a_module
17
+ end
18
+
19
+ def run
20
+ setup = self
21
+ a_module.extend(::ActiveSupport::Concern)
22
+ a_module.included do
23
+ ::EacRubyUtils::CommonConcern::ClassSetup.new(setup, self, :include).run
24
+ end
25
+ a_module.prepended do
26
+ ::EacRubyUtils::CommonConcern::ClassSetup.new(setup, self, :prepend).run
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/core_ext/hash/indifferent_access'
4
- require 'eac_ruby_utils/console/speaker'
5
- require 'eac_ruby_utils/envs/command/extra_options'
3
+ require 'eac_ruby_utils/core_ext'
6
4
  require 'eac_ruby_utils/envs/process'
7
5
  require 'eac_ruby_utils/envs/spawn'
8
6
  require 'pp'
@@ -11,8 +9,8 @@ require 'shellwords'
11
9
  module EacRubyUtils
12
10
  module Envs
13
11
  class Command
14
- include EacRubyUtils::Console::Speaker
15
- include EacRubyUtils::Envs::Command::ExtraOptions
12
+ require_sub __FILE__, include_modules: true
13
+ enable_console_speaker
16
14
 
17
15
  def initialize(env, command, extra_options = {})
18
16
  @env = env
@@ -47,7 +45,7 @@ module EacRubyUtils
47
45
  c = c.map { |x| escape(x) }.join(' ') if c.is_a?(Enumerable)
48
46
  append_command_options(
49
47
  @env.command_line(
50
- append_chdir(append_pipe(append_envvars(c)))
48
+ append_chdir(append_concat(append_envvars(c)))
51
49
  ),
52
50
  options
53
51
  )
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/struct'
4
+
5
+ module EacRubyUtils
6
+ module Envs
7
+ class Command
8
+ module Concat
9
+ def concat(operator, other_command)
10
+ duplicate_by_extra_options(concat: ::EacRubyUtils::Struct.new(
11
+ operator: operator, command: other_command
12
+ ))
13
+ end
14
+
15
+ def or(other_command)
16
+ concat('||', other_command)
17
+ end
18
+
19
+ def pipe(other_command)
20
+ concat('|', other_command)
21
+ end
22
+
23
+ private
24
+
25
+ def append_concat(command)
26
+ extra_options[:concat].if_present(command) do |v|
27
+ "#{command} #{v.operator} #{v.command.command}"
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ module Envs
5
+ class Command
6
+ module Envvars
7
+ def envvar(name, value)
8
+ duplicate_by_extra_options(envvars: envvars.merge(name => value))
9
+ end
10
+
11
+ private
12
+
13
+ def append_envvars(command)
14
+ e = envvars.map { |k, v| "#{Shellwords.escape(k)}=#{Shellwords.escape(v)}" }.join(' ')
15
+ e.present? ? "#{e} #{command}" : command
16
+ end
17
+
18
+ def envvars
19
+ extra_options[:envvars] ||= {}.with_indifferent_access
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -12,39 +12,18 @@ module EacRubyUtils
12
12
  duplicate_by_extra_options(chdir: dir)
13
13
  end
14
14
 
15
- def envvar(name, value)
16
- duplicate_by_extra_options(envvars: envvars.merge(name => value))
17
- end
18
-
19
15
  def status_result(status_code, result)
20
16
  duplicate_by_extra_options(status_results: status_results.merge(status_code => result))
21
17
  end
22
18
 
23
- def pipe(other_command)
24
- duplicate_by_extra_options(pipe: other_command)
25
- end
26
-
27
19
  private
28
20
 
29
21
  attr_reader :extra_options
30
22
 
31
- def envvars
32
- extra_options[:envvars] ||= {}.with_indifferent_access
33
- end
34
-
35
23
  def status_results
36
24
  extra_options[:status_results] ||= {}.with_indifferent_access
37
25
  end
38
26
 
39
- def append_envvars(command)
40
- e = envvars.map { |k, v| "#{Shellwords.escape(k)}=#{Shellwords.escape(v)}" }.join(' ')
41
- e.present? ? "#{e} #{command}" : command
42
- end
43
-
44
- def append_pipe(command)
45
- extra_options[:pipe].present? ? "#{command} | #{extra_options[:pipe].command}" : command
46
- end
47
-
48
27
  def append_chdir(command)
49
28
  extra_options[:chdir].present? ? "(cd '#{extra_options[:chdir]}' ; #{command} )" : command
50
29
  end
@@ -1,12 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_support/hash_with_indifferent_access'
4
+ require 'active_support/core_ext/module/delegation'
4
5
  require 'active_support/core_ext/object/blank'
5
6
 
6
7
  module EacRubyUtils
7
8
  class Struct
8
9
  def initialize(initial_data = {})
9
- self.data = ::ActiveSupport::HashWithIndifferentAccess.new(initial_data)
10
+ self.data = initial_data.symbolize_keys
10
11
  end
11
12
 
12
13
  def [](key)
@@ -19,6 +20,11 @@ module EacRubyUtils
19
20
  bool ? fetch(key).present? : data.fetch(key)
20
21
  end
21
22
 
23
+ def merge(other)
24
+ other = self.class.new(other) unless other.is_a?(self.class)
25
+ self.class.new(to_h.merge(other.to_h))
26
+ end
27
+
22
28
  def method_missing(method_name, *arguments, &block)
23
29
  property_method?(method_name) ? fetch(method_name) : super
24
30
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.54.0'
4
+ VERSION = '0.55.0'
5
5
  end
@@ -9,34 +9,47 @@ RSpec.describe ::EacRubyUtils::CommonConcern do
9
9
  end
10
10
  end
11
11
 
12
- module MyModule
13
- module ClassMethods
14
- def my_class_method
15
- 'class'
12
+ let(:stub_module) do
13
+ ::Module.new do
14
+ module ClassMethods # rubocop:disable RSpec/LeakyConstantDeclaration
15
+ def my_class_method
16
+ 'class'
17
+ end
16
18
  end
17
- end
18
19
 
19
- module InstanceMethods
20
- def my_instance_method
21
- 'instance'
20
+ module InstanceMethods # rubocop:disable RSpec/LeakyConstantDeclaration
21
+ def my_instance_method
22
+ 'instance'
23
+ end
22
24
  end
23
25
  end
24
26
  end
25
27
 
26
- class MyClass
27
- class << self
28
- attr_accessor :valor
28
+ let(:stub_class) do
29
+ ::Class.new do
30
+ class << self
31
+ attr_accessor :valor
32
+ end
33
+
34
+ def method1
35
+ 'from_stub_module'
36
+ end
29
37
  end
30
38
  end
31
39
 
32
- let(:subject) { MyClass.new }
40
+ let(:stub_class_instance) { stub_class.new }
33
41
 
34
42
  before do
35
- instance.setup(MyModule)
36
- MyClass.include MyModule
43
+ instance.setup(stub_module)
37
44
  end
38
45
 
39
- it { expect(subject.my_instance_method).to eq('instance') }
40
- it { expect(subject.class.my_class_method).to eq('class') }
41
- it { expect(subject.class.valor).to eq('changed') }
46
+ context 'when included' do
47
+ before do
48
+ stub_class.include stub_module
49
+ end
50
+
51
+ it { expect(stub_class_instance.my_instance_method).to eq('instance') }
52
+ it { expect(stub_class_instance.class.my_class_method).to eq('class') }
53
+ it { expect(stub_class_instance.class.valor).to eq('changed') }
54
+ end
42
55
  end
@@ -3,7 +3,8 @@
3
3
  require 'eac_ruby_utils/struct'
4
4
 
5
5
  RSpec.describe ::EacRubyUtils::Struct do
6
- let(:instance) { described_class.new(a: 1, b: '') }
6
+ let(:instance) { described_class.new('a' => 1, b: '') }
7
+ let(:other) { described_class.new('a' => 'm1', c: 'm2') }
7
8
 
8
9
  describe '#[]' do
9
10
  it { expect(instance[:a]).to eq(1) }
@@ -35,6 +36,12 @@ RSpec.describe ::EacRubyUtils::Struct do
35
36
  it { expect { instance.fetch('c?') }.to raise_error(::KeyError) }
36
37
  end
37
38
 
39
+ describe '#merge' do
40
+ let(:merged) { instance.merge(other) }
41
+
42
+ it { expect(merged.to_h).to eq(a: 'm1', b: '', c: 'm2') }
43
+ end
44
+
38
45
  describe '#property_method' do
39
46
  it { expect(instance.a).to eq(1) }
40
47
  it { expect(instance.a?).to eq(true) }
@@ -43,4 +50,8 @@ RSpec.describe ::EacRubyUtils::Struct do
43
50
  it { expect { instance.c }.to raise_error(::NoMethodError) }
44
51
  it { expect { instance.c? }.to raise_error(::NoMethodError) }
45
52
  end
53
+
54
+ describe '#to_h' do
55
+ it { expect(instance.to_h).to eq(a: 1, b: '') }
56
+ end
46
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.78.0
4
+ version: 0.82.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-12 00:00:00.000000000 Z
11
+ date: 2020-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -296,12 +296,15 @@ files:
296
296
  - lib/avm/eac_rails_base0/deploy.rb
297
297
  - lib/avm/eac_rails_base0/instance.rb
298
298
  - lib/avm/eac_rails_base1.rb
299
+ - lib/avm/eac_rails_base1/apache_host.rb
299
300
  - lib/avm/eac_rails_base1/instance.rb
300
301
  - lib/avm/eac_rails_base1/runner.rb
301
302
  - lib/avm/eac_rails_base1/runner/bundle.rb
302
303
  - lib/avm/eac_rails_base1/runner/code_runner.rb
304
+ - lib/avm/eac_rails_base1/runner/rails_server.rb
303
305
  - lib/avm/eac_rails_base1/runner_with/bundle.rb
304
306
  - lib/avm/eac_redmine_base0.rb
307
+ - lib/avm/eac_redmine_base0/apache_host.rb
305
308
  - lib/avm/eac_redmine_base0/core_update.rb
306
309
  - lib/avm/eac_redmine_base0/data_unit.rb
307
310
  - lib/avm/eac_redmine_base0/deploy.rb
@@ -434,6 +437,7 @@ files:
434
437
  - lib/avm/local_projects.rb
435
438
  - lib/avm/local_projects/instance.rb
436
439
  - lib/avm/patches.rb
440
+ - lib/avm/patches/class/i18n.rb
437
441
  - lib/avm/patches/eac_ruby_gems_utils/gem.rb
438
442
  - lib/avm/patches/i18n.rb
439
443
  - lib/avm/patches/object/i18n.rb
@@ -485,8 +489,6 @@ files:
485
489
  - lib/avm/tools/runner.rb
486
490
  - lib/avm/tools/runner/eac_rails_base0.rb
487
491
  - lib/avm/tools/runner/eac_rails_base0/apache_path.rb
488
- - lib/avm/tools/runner/eac_rails_base0/rails_server.rb
489
- - lib/avm/tools/runner/eac_rails_base0/runner.rb
490
492
  - lib/avm/tools/runner/eac_redmine_base0.rb
491
493
  - lib/avm/tools/runner/eac_redmine_base0/core_update.rb
492
494
  - lib/avm/tools/runner/eac_redmine_base0/docker.rb
@@ -508,6 +510,7 @@ files:
508
510
  - lib/avm/tools/runner/git/subrepo.rb
509
511
  - lib/avm/tools/runner/git/subrepo/check.rb
510
512
  - lib/avm/tools/runner/git/subrepo/clone.rb
513
+ - lib/avm/tools/runner/git/subrepo/fix.rb
511
514
  - lib/avm/tools/runner/instance.rb
512
515
  - lib/avm/tools/runner/instance/info.rb
513
516
  - lib/avm/tools/runner/launcher.rb
@@ -621,6 +624,7 @@ files:
621
624
  - vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb
622
625
  - vendor/eac_cli/lib/eac_cli/runner.rb
623
626
  - vendor/eac_cli/lib/eac_cli/runner/context.rb
627
+ - vendor/eac_cli/lib/eac_cli/runner/exit.rb
624
628
  - vendor/eac_cli/lib/eac_cli/runner_with.rb
625
629
  - vendor/eac_cli/lib/eac_cli/runner_with/help.rb
626
630
  - vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb
@@ -630,6 +634,7 @@ files:
630
634
  - vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb
631
635
  - vendor/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb
632
636
  - vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb
637
+ - vendor/eac_cli/spec/lib/eac_cli/runner_with/help_spec.rb
633
638
  - vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb
634
639
  - vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb
635
640
  - vendor/eac_cli/spec/rubocop_spec.rb
@@ -902,6 +907,8 @@ files:
902
907
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
903
908
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/by_reference.rb
904
909
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb
910
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/class_setup.rb
911
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb
905
912
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb
906
913
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/configs.rb
907
914
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/base.rb
@@ -928,6 +935,8 @@ files:
928
935
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs.rb
929
936
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/base_env.rb
930
937
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb
938
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/concat.rb
939
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/envvars.rb
931
940
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb
932
941
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/executable.rb
933
942
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/file.rb
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/eac_rails_base1/runner_with/bundle'
4
- require 'avm/instances/entry_keys'
5
- require 'eac_cli/core_ext'
6
- require 'eac_ruby_utils/console/docopt_runner'
7
- require 'shellwords'
8
-
9
- module Avm
10
- module Tools
11
- class Runner < ::EacRubyUtils::Console::DocoptRunner
12
- class EacRailsBase0 < ::Avm::EacRailsBase1::Runner
13
- class RailsServer
14
- DEFAULT_RAILS_ENVIRONMENT = 'development'
15
- runner_with ::Avm::EacRailsBase1::RunnerWith::Bundle
16
- runner_definition do
17
- desc 'Run the embbeded Rails web server.'
18
- end
19
-
20
- def run
21
- infov 'Environment', rails_environment
22
- infov 'Bundle args', ::Shellwords.join(bundle_args)
23
- infov 'Result', bundle_command.system
24
- end
25
-
26
- protected
27
-
28
- def bundle_args
29
- ['exec', 'rails', 'server', '--port',
30
- runner_context.call(:instance).read_entry(::Avm::Instances::EntryKeys::WEB_PORT)]
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/eac_rails_base1/runner/code_runner'
4
-
5
- module Avm
6
- module Tools
7
- class Runner < ::EacRubyUtils::Console::DocoptRunner
8
- class EacRailsBase0 < ::Avm::EacRailsBase1::Runner
9
- class Runner < ::Avm::EacRailsBase1::Runner::CodeRunner
10
- end
11
- end
12
- end
13
- end
14
- end