avm-tools 0.80.0 → 0.84.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) 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/eac_writings_base1.rb +9 -0
  10. data/lib/avm/eac_writings_base1/apache_host.rb +17 -0
  11. data/lib/avm/eac_writings_base1/build.rb +45 -0
  12. data/lib/avm/eac_writings_base1/build/file.rb +28 -0
  13. data/lib/avm/eac_writings_base1/deploy.rb +26 -0
  14. data/lib/avm/eac_writings_base1/instance.rb +11 -0
  15. data/lib/avm/eac_writings_base1/project.rb +13 -0
  16. data/lib/avm/executables.rb +1 -1
  17. data/lib/avm/tools/runner/eac_writings_base1.rb +15 -0
  18. data/lib/avm/tools/runner/local_project/eac_writings_base1.rb +32 -0
  19. data/lib/avm/tools/runner/local_project/eac_writings_base1/build.rb +48 -0
  20. data/lib/avm/tools/version.rb +1 -1
  21. data/vendor/eac_cli/eac_cli.gemspec +1 -1
  22. data/vendor/eac_cli/lib/eac_cli/parser.rb +6 -4
  23. data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +4 -0
  24. data/vendor/eac_cli/lib/eac_cli/runner.rb +10 -2
  25. data/vendor/eac_cli/lib/eac_cli/runner/exit.rb +13 -0
  26. data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +17 -0
  27. data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +6 -1
  28. data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
  29. data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +6 -3
  30. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/help_spec.rb +42 -0
  31. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +29 -1
  32. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +2 -50
  33. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/class_setup.rb +52 -0
  34. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb +31 -0
  35. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/basename_sub.rb +2 -2
  36. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +7 -1
  37. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  38. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +30 -17
  39. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +12 -1
  40. metadata +19 -4
  41. data/lib/avm/tools/runner/eac_rails_base0/rails_server.rb +0 -36
  42. 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: '0517668b390f4bfcd0ade6b28b127de99e7b309e54633353bae6a0e558c36054'
4
- data.tar.gz: d6cb8cb3880f9929fe7f5bea9ed794934a50e2aed96fccbe4c1f42c5cc2e2524
3
+ metadata.gz: d6a742d3c0263c2512a52c5109e56336b275560ed7db3c94fe42792021c1762a
4
+ data.tar.gz: 3efdf68bf27d110a3a17ea012b208b6a59b40a05158f360f018423917fc55089
5
5
  SHA512:
6
- metadata.gz: f46b14fadb4d557a6e3af527649b9237b7e2281af7828bc646c031c326f9441d2720e07d878b161c42de90d0770edaf1df67b006b77b233b1a1b21352e346903
7
- data.tar.gz: 8e2bf840b44027bfbe263607654e11ae4557d0bdbb0867e3cfad51f823f7e9427205c3ed296461c2c5414d354ad505d64e3a76a37256175d21bc5f947cbeaf8f
6
+ metadata.gz: 1c1fcb15c0f44dc6a91081eed404f64e1a729fce4de417ada083f09b23149a7192b33d8ed67a4d087de84c161f43aca09b10dd9a51ec4c1ce645354c2cd62b96
7
+ data.tar.gz: 04bae047386b129d906a5ed2f8663ba0c0c3019a48b0b63603ac431ad4cc17163b92bae642daa9785d3c8d8277e1643d65da5ff612815e1110ae0566a8258086
@@ -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,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module EacWritingsBase1
7
+ require_sub __FILE__
8
+ end
9
+ 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 EacWritingsBase1
7
+ class ApacheHost < ::Avm::EacWebappBase0::ApacheHost
8
+ def document_root
9
+ instance.read_entry(::Avm::Instances::EntryKeys::FS_PATH)
10
+ end
11
+
12
+ def extra_content
13
+ ''
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/fs/clearable_directory'
5
+
6
+ module Avm
7
+ module EacWritingsBase1
8
+ class Build
9
+ require_sub __FILE__
10
+ enable_console_speaker
11
+ enable_simple_cache
12
+ enable_listable
13
+ lists.add_symbol :option, :target_directory
14
+ common_constructor :project, :options, default: [{}] do
15
+ self.options = self.class.lists.option.hash_keys_validate!(options.symbolize_keys)
16
+ end
17
+
18
+ def run
19
+ infov 'Files to build', source_files.count
20
+ target_directory.clear
21
+ source_files.each(&:run)
22
+ end
23
+
24
+ def default_target_directory
25
+ project.root.join('build')
26
+ end
27
+
28
+ def target_directory
29
+ ::EacRubyUtils::Fs::ClearableDirectory.new(
30
+ options[OPTION_TARGET_DIRECTORY] || default_target_directory
31
+ )
32
+ end
33
+
34
+ def source_files_uncached
35
+ r = []
36
+ project.root.children.each do |child|
37
+ next unless child.extname == '.asc'
38
+
39
+ r << ::Avm::EacWritingsBase1::Build::File.new(self, child.basename)
40
+ end
41
+ r
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/executables'
4
+
5
+ module Avm
6
+ module EacWritingsBase1
7
+ class Build
8
+ class File
9
+ enable_console_speaker
10
+ common_constructor :build, :subpath
11
+
12
+ def run
13
+ infov 'Building', subpath
14
+ target_path.parent.mkpath
15
+ ::Avm::Executables.asciidoc.command('--out-file', target_path, source_path).system!
16
+ end
17
+
18
+ def source_path
19
+ build.project.root.join(subpath)
20
+ end
21
+
22
+ def target_path
23
+ build.target_directory.join(subpath).basename_sub('.*') { |b| "#{b}.html" }
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_webapp_base0/deploy'
4
+ require 'avm/eac_writings_base1/project'
5
+ require 'avm/eac_writings_base1/build'
6
+
7
+ module Avm
8
+ module EacWritingsBase1
9
+ class Deploy < ::Avm::EacWebappBase0::Deploy
10
+ def build_content
11
+ ::Avm::EacWritingsBase1::Build.new(
12
+ project,
13
+ ::Avm::EacWritingsBase1::Build::OPTION_TARGET_DIRECTORY => build_dir
14
+ ).run
15
+ end
16
+
17
+ private
18
+
19
+ def project_uncached
20
+ ::Avm::EacWritingsBase1::Project.new(
21
+ instance.source_instance.read_entry(::Avm::Instances::EntryKeys::FS_PATH)
22
+ )
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_webapp_base0/instance'
4
+
5
+ module Avm
6
+ module EacWritingsBase1
7
+ class Instance < ::Avm::EacWebappBase0::Instance
8
+ FILES_UNITS = {}.freeze
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module EacWritingsBase1
7
+ class Project
8
+ common_constructor :root do
9
+ self.root = root.to_pathname
10
+ end
11
+ end
12
+ end
13
+ end
@@ -14,7 +14,7 @@ module Avm
14
14
 
15
15
  private
16
16
 
17
- %w[docker file git latex php-cs-fixer tidy yapf xdg-open].each do |program|
17
+ %w[asciidoc docker file git latex php-cs-fixer tidy yapf xdg-open].each do |program|
18
18
  define_method(program.underscore + '_uncached') do
19
19
  env.executable(program, '--version')
20
20
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_webapp_base0/runner'
4
+ require 'avm/eac_writings_base1'
5
+ require 'eac_ruby_utils/console/docopt_runner'
6
+
7
+ module Avm
8
+ module Tools
9
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
10
+ class EacWritingsBase1 < ::Avm::EacWebappBase0::Runner
11
+ require_sub __FILE__
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/core_ext'
4
+ require 'eac_ruby_utils/console/docopt_runner'
5
+
6
+ module Avm
7
+ module Tools
8
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
9
+ class LocalProject < ::EacRubyUtils::Console::DocoptRunner
10
+ class EacWritingsBase1
11
+ require_sub __FILE__
12
+
13
+ runner_with :help, :subcommands do
14
+ desc 'EacWritingsBase0 utitilies for local projects.'
15
+ subcommands
16
+ end
17
+
18
+ def project_banner
19
+ infov 'Project', project.name
20
+ infov 'Path', project.root
21
+ end
22
+
23
+ private
24
+
25
+ def project_uncached
26
+ ::Avm::EacWritingsBase0::Project.new(runner_context.call(:instance_path))
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_writings_base1/build'
4
+ require 'avm/eac_writings_base1/project'
5
+ require 'eac_cli/core_ext'
6
+ require 'eac_ruby_utils/console/docopt_runner'
7
+
8
+ module Avm
9
+ module Tools
10
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
11
+ class LocalProject < ::EacRubyUtils::Console::DocoptRunner
12
+ class EacWritingsBase1
13
+ class Build
14
+ runner_with :help do
15
+ desc 'Build the project'
16
+ arg_opt '-d', '--target-dir', 'Directory to build'
17
+ end
18
+
19
+ def run
20
+ start_banner
21
+ build.run
22
+ end
23
+
24
+ private
25
+
26
+ def build_uncached
27
+ ::Avm::EacWritingsBase1::Build.new(runner_context.call(:project),
28
+ target_directory: parsed.target_dir)
29
+ end
30
+
31
+ def default_target_directory
32
+ runner_context.call(:project).root.join('build')
33
+ end
34
+
35
+ def start_banner
36
+ runner_context.call(:project_banner)
37
+ infov 'Target directory', build.target_directory
38
+ end
39
+ #
40
+ # def target_directory_uncached
41
+ # .if_present(default_target_directory).to_pathname
42
+ # end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Tools
5
- VERSION = '0.80.0'
5
+ VERSION = '0.84.0'
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,23 @@ 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
+ r = ::EacCli::Docopt::DocBuilder.new(self.class.runner_definition).to_s
31
+ r += help_extra_text if respond_to?(:help_extra_text)
32
+ r
16
33
  end
17
34
  end
18
35
  end
@@ -31,6 +31,11 @@ module EacCli
31
31
  end
32
32
  end
33
33
 
34
+ def help_extra_text
35
+ (['Subcommands:'] + available_subcommands.keys.map { |s| " #{s}" })
36
+ .map { |v| "#{v}\n" }.join
37
+ end
38
+
34
39
  def method_missing(method_name, *arguments, &block)
35
40
  return run_with_subcommand(*arguments, &block) if
36
41
  run_with_subcommand_alias_run?(method_name)
@@ -44,7 +49,7 @@ module EacCli
44
49
 
45
50
  def run_with_subcommand
46
51
  if subcommand_name
47
- subcommand_runner.run
52
+ subcommand_runner.run_run
48
53
  else
49
54
  run_without_subcommand
50
55
  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.4'
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
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_cli/runner'
4
+ require 'eac_cli/runner_with/help'
4
5
  require 'eac_cli/runner_with/subcommands'
5
6
 
6
7
  RSpec.describe ::EacCli::RunnerWith::Subcommands do
@@ -8,7 +9,6 @@ RSpec.describe ::EacCli::RunnerWith::Subcommands do
8
9
  the_module = described_class
9
10
  the_child = child_runner
10
11
  Class.new do
11
- include ::EacCli::Runner
12
12
  include the_module
13
13
  const_set('ChildCmd', the_child)
14
14
 
@@ -54,4 +54,32 @@ RSpec.describe ::EacCli::RunnerWith::Subcommands do
54
54
  expect { instance.run }.to raise_error(::EacCli::Parser::Error)
55
55
  end
56
56
  end
57
+
58
+ context 'with help' do
59
+ let(:instance) { parent_runner.create(%w[--help]) }
60
+ let(:expected_output) do
61
+ <<~OUTPUT
62
+ A stub root runner.
63
+
64
+ Usage:
65
+ __PROGRAM__ [options] __SUBCOMMANDS__ [<subcommand_args>...]
66
+ __PROGRAM__ --help
67
+
68
+ Options:
69
+ -r --root-var=<value> A root variable.
70
+ -h --help Show help.
71
+
72
+ Subcommands:
73
+ child-cmd
74
+ OUTPUT
75
+ end
76
+
77
+ before do
78
+ parent_runner.include(::EacCli::RunnerWith::Help)
79
+ end
80
+
81
+ it 'show help text' do
82
+ expect { instance.run_run }.to output(expected_output).to_stdout_from_any_process
83
+ end
84
+ end
57
85
  end
@@ -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
@@ -3,7 +3,7 @@
3
3
  require 'pathname'
4
4
 
5
5
  class Pathname
6
- def basename_sub
7
- parent.join(yield(basename))
6
+ def basename_sub(suffix = '')
7
+ parent.join(yield(basename(suffix)))
8
8
  end
9
9
  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.55.0'
4
+ VERSION = '0.56.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.80.0
4
+ version: 0.84.0
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-16 00:00:00.000000000 Z
11
+ date: 2020-12-25 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
@@ -343,6 +346,13 @@ files:
343
346
  - lib/avm/eac_writings_base0/project_build.rb
344
347
  - lib/avm/eac_writings_base0/project_build/chapters_content.rb
345
348
  - lib/avm/eac_writings_base0/project_build/copy_files.rb
349
+ - lib/avm/eac_writings_base1.rb
350
+ - lib/avm/eac_writings_base1/apache_host.rb
351
+ - lib/avm/eac_writings_base1/build.rb
352
+ - lib/avm/eac_writings_base1/build/file.rb
353
+ - lib/avm/eac_writings_base1/deploy.rb
354
+ - lib/avm/eac_writings_base1/instance.rb
355
+ - lib/avm/eac_writings_base1/project.rb
346
356
  - lib/avm/executables.rb
347
357
  - lib/avm/files.rb
348
358
  - lib/avm/files/appendable.rb
@@ -486,14 +496,13 @@ files:
486
496
  - lib/avm/tools/runner.rb
487
497
  - lib/avm/tools/runner/eac_rails_base0.rb
488
498
  - lib/avm/tools/runner/eac_rails_base0/apache_path.rb
489
- - lib/avm/tools/runner/eac_rails_base0/rails_server.rb
490
- - lib/avm/tools/runner/eac_rails_base0/runner.rb
491
499
  - lib/avm/tools/runner/eac_redmine_base0.rb
492
500
  - lib/avm/tools/runner/eac_redmine_base0/core_update.rb
493
501
  - lib/avm/tools/runner/eac_redmine_base0/docker.rb
494
502
  - lib/avm/tools/runner/eac_redmine_base0/project_rename.rb
495
503
  - lib/avm/tools/runner/eac_wordpress_base0.rb
496
504
  - lib/avm/tools/runner/eac_writings_base0.rb
505
+ - lib/avm/tools/runner/eac_writings_base1.rb
497
506
  - lib/avm/tools/runner/files.rb
498
507
  - lib/avm/tools/runner/files/format.rb
499
508
  - lib/avm/tools/runner/files/rotate.rb
@@ -521,6 +530,8 @@ files:
521
530
  - lib/avm/tools/runner/local_project/eac_writings_base0/build_chapters.rb
522
531
  - lib/avm/tools/runner/local_project/eac_writings_base0/build_single.rb
523
532
  - lib/avm/tools/runner/local_project/eac_writings_base0/info.rb
533
+ - lib/avm/tools/runner/local_project/eac_writings_base1.rb
534
+ - lib/avm/tools/runner/local_project/eac_writings_base1/build.rb
524
535
  - lib/avm/tools/runner/local_project/info.rb
525
536
  - lib/avm/tools/runner/local_project/ruby.rb
526
537
  - lib/avm/tools/runner/local_project/ruby/bundler.rb
@@ -623,6 +634,7 @@ files:
623
634
  - vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb
624
635
  - vendor/eac_cli/lib/eac_cli/runner.rb
625
636
  - vendor/eac_cli/lib/eac_cli/runner/context.rb
637
+ - vendor/eac_cli/lib/eac_cli/runner/exit.rb
626
638
  - vendor/eac_cli/lib/eac_cli/runner_with.rb
627
639
  - vendor/eac_cli/lib/eac_cli/runner_with/help.rb
628
640
  - vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb
@@ -632,6 +644,7 @@ files:
632
644
  - vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb
633
645
  - vendor/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb
634
646
  - vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb
647
+ - vendor/eac_cli/spec/lib/eac_cli/runner_with/help_spec.rb
635
648
  - vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb
636
649
  - vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb
637
650
  - vendor/eac_cli/spec/rubocop_spec.rb
@@ -904,6 +917,8 @@ files:
904
917
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
905
918
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/by_reference.rb
906
919
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb
920
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/class_setup.rb
921
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb
907
922
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb
908
923
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/configs.rb
909
924
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/base.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