eac_tools 0.8.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +25 -19
  3. data/lib/eac_tools/version.rb +1 -1
  4. data/sub/avm/lib/avm/application_stereotypes/base.rb +21 -0
  5. data/sub/avm/lib/avm/application_stereotypes.rb +9 -0
  6. data/sub/avm/lib/avm/applications/base/stereotype.rb +31 -0
  7. data/sub/avm/lib/avm/applications/base.rb +45 -0
  8. data/sub/avm/lib/avm/applications.rb +9 -0
  9. data/sub/avm/lib/avm/docker/image.rb +12 -2
  10. data/sub/avm/lib/avm/instances/base.rb +7 -2
  11. data/sub/avm/lib/avm/instances.rb +1 -1
  12. data/sub/avm/lib/avm/registry/application_stereotypes/build_available.rb +46 -0
  13. data/sub/avm/lib/avm/registry/application_stereotypes/stereotype_builder.rb +30 -0
  14. data/sub/avm/lib/avm/registry/application_stereotypes.rb +52 -0
  15. data/sub/avm/lib/avm/registry/{base.rb → from_gems.rb} +13 -4
  16. data/sub/avm/lib/avm/registry/instances.rb +16 -0
  17. data/sub/avm/lib/avm/registry/runners.rb +10 -0
  18. data/sub/avm/lib/avm/registry/scms.rb +10 -0
  19. data/sub/avm/lib/avm/registry/sources.rb +10 -0
  20. data/sub/avm/lib/avm/registry/with_path/cache.rb +2 -2
  21. data/sub/avm/lib/avm/registry/with_path.rb +8 -2
  22. data/sub/avm/lib/avm/registry.rb +3 -7
  23. data/sub/avm/lib/avm/rspec/shared_examples/not_in_avm_registry.rb +1 -1
  24. data/sub/avm/lib/avm/scms/base.rb +2 -0
  25. data/sub/avm/lib/avm/sources/base/instance.rb +2 -2
  26. data/sub/avm/lib/avm/sources/base.rb +4 -0
  27. data/sub/avm/lib/avm/version.rb +1 -1
  28. data/sub/avm/lib/avm/with_application_stereotype.rb +23 -0
  29. data/sub/avm/lib/avm/with_dynamic_runners.rb +42 -0
  30. data/sub/{avm-tools/spec/lib/avm/instances/application_spec.rb → avm/spec/lib/avm/applications/base_spec.rb} +3 -3
  31. data/sub/{avm-tools/spec/lib/avm/instances/application_spec_fixture.yml → avm/spec/lib/avm/applications/base_spec_fixture.yml} +0 -0
  32. data/sub/{avm-tools → avm}/spec/lib/avm/instances/base_spec.rb +0 -0
  33. data/sub/{avm-tools → avm}/spec/lib/avm/instances/base_spec_configs_storage.yml +0 -0
  34. data/sub/avm-eac_generic_base0/avm-eac_generic_base0.gemspec +2 -2
  35. data/sub/avm-eac_generic_base0/lib/avm/eac_generic_base0/sources/docker/runner.rb +61 -0
  36. data/sub/avm-eac_generic_base0/lib/avm/eac_generic_base0/sources/docker.rb +13 -0
  37. data/sub/avm-eac_generic_base0/lib/avm/eac_generic_base0/version.rb +1 -1
  38. data/sub/avm-eac_redmine_base0/avm-eac_redmine_base0.gemspec +2 -0
  39. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base.rb +14 -0
  40. data/sub/{avm-tools/lib/avm/tools/runner/eac_redmine_base0 → avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners}/docker.rb +3 -3
  41. data/sub/{avm-tools/lib/avm/tools/runner/eac_redmine_base0 → avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners}/project_rename.rb +3 -3
  42. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners.rb +13 -0
  43. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/runners/base.rb +25 -0
  44. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources/runners/core_update.rb +1 -3
  45. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources/runners/docker.rb +19 -0
  46. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/version.rb +1 -1
  47. data/sub/avm-tools/avm-tools.gemspec +1 -2
  48. data/sub/avm-tools/lib/avm/tools/runner/application_stereotypes/list.rb +31 -0
  49. data/sub/avm-tools/lib/avm/tools/runner/application_stereotypes.rb +16 -0
  50. data/sub/avm-tools/lib/avm/tools/runner/instance/info.rb +1 -0
  51. data/sub/avm-tools/lib/avm/tools/runner/instance.rb +6 -1
  52. data/sub/avm-tools/lib/avm/tools/version.rb +1 -1
  53. data/sub/eac_docker/Gemfile +8 -0
  54. data/sub/{avm-tools/sub/eac_docker → eac_docker}/eac_docker.gemspec +3 -3
  55. data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/container.rb +4 -3
  56. data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/debug.rb +0 -0
  57. data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/executables.rb +0 -0
  58. data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/images/base.rb +0 -0
  59. data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/images/coded.rb +0 -0
  60. data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/images/named.rb +0 -0
  61. data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/images/templatized.rb +0 -0
  62. data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/images.rb +0 -0
  63. data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/registry.rb +0 -0
  64. data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/rspec/setup.rb +0 -0
  65. data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/rspec.rb +0 -0
  66. data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/version.rb +1 -1
  67. data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker.rb +0 -0
  68. data/sub/{avm-tools/sub/eac_docker → eac_docker}/spec/lib/eac_docker/executables_spec.rb +0 -0
  69. data/sub/{avm-tools/sub/eac_docker → eac_docker}/spec/lib/eac_docker/images/coded_spec.rb +0 -0
  70. data/sub/{avm-tools/sub/eac_docker → eac_docker}/spec/lib/eac_docker/images/coded_spec_files/image1/Dockerfile +0 -0
  71. data/sub/{avm-tools/sub/eac_docker → eac_docker}/spec/lib/eac_docker/images/templatized_spec.rb +0 -0
  72. data/sub/{avm-tools/sub/eac_docker → eac_docker}/spec/lib/eac_docker/images/templatized_spec_files/stub_docker_image/Dockerfile +0 -0
  73. data/sub/{avm-tools/sub/eac_docker → eac_docker}/spec/rubocop_spec.rb +0 -0
  74. data/sub/{avm-tools/sub/eac_docker → eac_docker}/spec/spec_helper.rb +0 -0
  75. data/sub/eac_ruby_utils/lib/eac_ruby_utils/immutable/array_accessor.rb +22 -5
  76. data/sub/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  77. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/immutable_spec.rb +34 -0
  78. metadata +62 -50
  79. data/sub/avm/lib/avm/instances/application.rb +0 -29
  80. data/sub/avm/lib/avm/sources/base/runners.rb +0 -47
  81. data/sub/avm-tools/Gemfile.lock +0 -291
  82. data/sub/avm-tools/lib/avm/tools/runner/eac_redmine_base0/dev_docker.rb +0 -17
  83. data/sub/avm-tools/lib/avm/tools/runner/eac_redmine_base0.rb +0 -15
  84. data/sub/avm-tools/sub/eac_docker/Gemfile +0 -5
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'avm/registry'
4
4
  require 'avm/scms/null'
5
+ require 'avm/with_application_stereotype'
6
+ require 'avm/with_dynamic_runners'
5
7
  require 'eac_git'
6
8
  require 'eac_ruby_utils/core_ext'
7
9
 
@@ -9,6 +11,8 @@ module Avm
9
11
  module Sources
10
12
  class Base
11
13
  require_sub __FILE__, include_modules: true
14
+ include ::Avm::WithApplicationStereotype
15
+ include ::Avm::WithDynamicRunners
12
16
  compare_by :path
13
17
  enable_abstract_methods
14
18
  enable_simple_cache
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Avm
4
- VERSION = '0.26.0'
4
+ VERSION = '0.29.0'
5
5
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner_with/subcommands'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module WithApplicationStereotype
8
+ common_concern do
9
+ include ClassMethods
10
+ end
11
+
12
+ module ClassMethods
13
+ # @return [Module]
14
+ def stereotype_namespace_module
15
+ module_parent.module_parent
16
+ end
17
+ end
18
+
19
+ def stereotype_namespace_module
20
+ self.class.stereotype_namespace_module
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner_with/subcommands'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module WithDynamicRunners
8
+ # @return [Hash<String, EacCli::Runner>]
9
+ def extra_available_subcommands
10
+ extra_available_subcommands_from_runners_module
11
+ end
12
+
13
+ # @return [Hash<String, EacCli::Runner>]
14
+ def extra_available_subcommands_from_runners_module
15
+ self.class.ancestors.reverse.inject({}) do |a, e|
16
+ a.merge(RunnersFromModule.new(e).result)
17
+ end
18
+ end
19
+
20
+ class RunnersFromModule
21
+ enable_simple_cache
22
+ common_constructor :the_module
23
+
24
+ # @return [Hash<String, EacCli::Runner>]
25
+ def result
26
+ return {} if runners_module.blank?
27
+
28
+ ::EacCli::RunnerWith::Subcommands.subcommands_from_module(runners_module)
29
+ end
30
+
31
+ def runners_module_uncached
32
+ return nil if the_module.module_parent.blank?
33
+
34
+ begin
35
+ the_module.module_parent.const_get('Runners')
36
+ rescue ::NameError
37
+ nil
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/instances/application'
3
+ require 'avm/applications/base'
4
4
 
5
- RSpec.describe ::Avm::Instances::Application do
5
+ RSpec.describe ::Avm::Applications::Base do
6
6
  let(:instance) { described_class.new('avm-tools') }
7
7
 
8
8
  ::EacRubyUtils::Rspec
9
9
  .default_setup
10
- .stub_eac_config_node(self, ::File.join(__dir__, 'application_spec_fixture.yml'))
10
+ .stub_eac_config_node(self, ::File.join(__dir__, 'base_spec_fixture.yml'))
11
11
 
12
12
  describe '#id' do
13
13
  it { expect(instance.id).to eq('avm-tools') }
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = Dir['{lib,locale}/**/*']
14
14
 
15
- s.add_dependency 'avm', '~> 0.24'
16
- s.add_dependency 'eac_ruby_utils', '~> 0.05', '>= 0.95.2'
15
+ s.add_dependency 'avm', '~> 0.28'
16
+ s.add_dependency 'eac_ruby_utils', '~> 0.96'
17
17
 
18
18
  s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5.1'
19
19
  end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/core_ext'
4
+
5
+ module Avm
6
+ module EacGenericBase0
7
+ module Sources
8
+ module Docker
9
+ class Runner
10
+ CONTAINER_SOURCE_PATH = '/app'
11
+
12
+ enable_abstract_methods
13
+ abstract_methods :docker_image
14
+
15
+ runner_with :help do
16
+ desc 'Run a Docker container with source mapped.'
17
+ arg_opt '-c', '--command-arg', 'Arguments for [COMMAND] [ARG...].', optional: true,
18
+ repeat: true
19
+ end
20
+
21
+ def run
22
+ start_banner
23
+ docker_container.run_command.system!
24
+ end
25
+
26
+ def start_banner
27
+ infov 'Image', docker_image
28
+ infov 'Command', ::Shellwords.join(command_args)
29
+ end
30
+
31
+ def bash_command_args
32
+ %w[/bin/bash]
33
+ end
34
+
35
+ def command_args
36
+ if parsed.command_arg.any?
37
+ parsed.command_arg
38
+ else
39
+ default_command_args
40
+ end
41
+ end
42
+
43
+ def default_command_args
44
+ bash_command_args
45
+ end
46
+
47
+ def docker_container
48
+ docker_image.container
49
+ .volume(runner_context.call(:subject).path, CONTAINER_SOURCE_PATH)
50
+ .interactive(true).tty(true).command_args(command_args)
51
+ end
52
+
53
+ # @return [EacDocker::Images::Base]
54
+ def docker_image
55
+ raise_abstract_method __method__
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module EacGenericBase0
7
+ module Sources
8
+ module Docker
9
+ require_sub __FILE__
10
+ end
11
+ end
12
+ end
13
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module EacGenericBase0
5
- VERSION = '0.3.0'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
@@ -12,6 +12,8 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = Dir['{lib,locale,template}/**/*']
14
14
 
15
+ s.add_dependency 'avm', '~> 0.29'
16
+ s.add_dependency 'avm-eac_generic_base0', '~> 0.4'
15
17
  s.add_dependency 'avm-eac_rails_base1', '~> 0.4', '>= 0.4.1'
16
18
  s.add_dependency 'avm-eac_ubuntu_base0', '~> 0.3'
17
19
  s.add_dependency 'curb', '~> 0.9.11'
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/base'
4
+ require 'avm/eac_redmine_base0/instances/runners'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module Avm
8
+ module EacRedmineBase0
9
+ module Instances
10
+ class Base < ::Avm::Instances::Base
11
+ end
12
+ end
13
+ end
14
+ end
@@ -3,9 +3,9 @@
3
3
  require 'avm/docker/runner'
4
4
 
5
5
  module Avm
6
- module Tools
7
- class Runner
8
- class EacRedmineBase0 < ::Avm::EacRailsBase1::Runner
6
+ module EacRedmineBase0
7
+ module Instances
8
+ module Runners
9
9
  class Docker < ::Avm::Docker::Runner
10
10
  def use_default_registry?
11
11
  false
@@ -4,9 +4,9 @@ require 'eac_cli/core_ext'
4
4
  require 'avm/eac_rails_base1/runner/code_runner'
5
5
 
6
6
  module Avm
7
- module Tools
8
- class Runner
9
- class EacRedmineBase0 < ::Avm::EacRailsBase1::Runner
7
+ module EacRedmineBase0
8
+ module Instances
9
+ module Runners
10
10
  class ProjectRename
11
11
  runner_with ::Avm::EacRailsBase1::RunnerWith::Bundle do
12
12
  pos_arg :from
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module EacRedmineBase0
7
+ module Instances
8
+ module Runners
9
+ require_sub __FILE__
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_redmine_base0/instance'
4
+ require 'avm/eac_redmine_base0/deploy'
5
+ require 'avm/eac_redmine_base0/apache_host'
6
+ require 'avm/eac_rails_base1/runner'
7
+ require 'eac_ruby_utils/core_ext'
8
+
9
+ module Avm
10
+ module EacRedmineBase0
11
+ module Runners
12
+ class Base < ::Avm::EacRailsBase1::Runner
13
+ require_sub __FILE__
14
+
15
+ STEREOTYPE_NAME = 'EacRedmineBase0'
16
+
17
+ class << self
18
+ def stereotype_name
19
+ STEREOTYPE_NAME
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'avm/eac_rails_base1/sources/base'
3
4
  require 'avm/eac_redmine_base0/core_update'
4
5
  require 'eac_cli/core_ext'
5
- require 'avm/eac_rails_base1/sources/base'
6
- require 'avm/eac_redmine_base0/sources/runners'
7
- require 'eac_ruby_utils/core_ext'
8
6
 
9
7
  module Avm
10
8
  module EacRedmineBase0
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_generic_base0/sources/docker/runner'
4
+ require 'avm/eac_ubuntu_base0/docker_image'
5
+
6
+ module Avm
7
+ module EacRedmineBase0
8
+ module Sources
9
+ module Runners
10
+ class Docker < ::Avm::EacGenericBase0::Sources::Docker::Runner
11
+ # @return [Avm::EacUbuntuBase0::DockerImage]
12
+ def docker_image
13
+ ::Avm::EacUbuntuBase0::DockerImage.new
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module EacRedmineBase0
5
- VERSION = '0.9.1'
5
+ VERSION = '0.11.0'
6
6
  end
7
7
  end
@@ -15,10 +15,9 @@ Gem::Specification.new do |s|
15
15
  s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
16
16
 
17
17
  s.add_dependency 'aranha-parsers', '~> 0.4'
18
- s.add_dependency 'avm', '~> 0.22'
18
+ s.add_dependency 'avm', '~> 0.27'
19
19
  s.add_dependency 'avm-eac_asciidoctor_base0', '~> 0.3', '>= 0.3.4'
20
20
  s.add_dependency 'avm-eac_rails_base0', '~> 0.3'
21
- s.add_dependency 'avm-eac_redmine_base0', '~> 0.5', '>= 0.5.2'
22
21
  s.add_dependency 'avm-eac_ruby_base1', '~> 0.8'
23
22
  s.add_dependency 'avm-eac_ubuntu_base0', '~> 0.3'
24
23
  s.add_dependency 'avm-files', '~> 0.1'
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/tools/core_ext'
4
+
5
+ module Avm
6
+ module Tools
7
+ class Runner
8
+ class ApplicationStereotypes
9
+ class List
10
+ runner_with :help, :output
11
+
12
+ def run
13
+ infov 'Found', stereotypes.count
14
+ run_output
15
+ end
16
+
17
+ def output_content
18
+ stereotypes.map { |s| "#{s}\n" }.join
19
+ end
20
+
21
+ private
22
+
23
+ def stereotypes
24
+ ::Avm::Registry.application_stereotypes.available
25
+ .sort_by { |s| [s.name, s.namespace_module] }
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/core_ext'
4
+
5
+ module Avm
6
+ module Tools
7
+ class Runner
8
+ class ApplicationStereotypes
9
+ require_sub __FILE__
10
+ runner_with :help, :subcommands do
11
+ subcommands
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -22,6 +22,7 @@ module Avm
22
22
  def base_banner
23
23
  infov 'ID', instance.id
24
24
  infov 'Application ID', instance.application.id
25
+ infov 'Application stereotype', instance.application.stereotype
25
26
  infov 'Suffix', instance.suffix
26
27
  end
27
28
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'avm/instances/base'
4
+ require 'avm/registry'
4
5
  require 'eac_cli/core_ext'
5
6
 
6
7
  module Avm
@@ -14,10 +15,14 @@ module Avm
14
15
  subcommands
15
16
  end
16
17
 
18
+ def extra_available_subcommands
19
+ instance.if_present({}, &:extra_available_subcommands)
20
+ end
21
+
17
22
  private
18
23
 
19
24
  def instance_uncached
20
- ::Avm::Instances::Base.by_id(parsed.instance_id)
25
+ ::Avm::Registry.instances.detect(parsed.instance_id)
21
26
  end
22
27
  end
23
28
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Tools
5
- VERSION = '0.122.0'
5
+ VERSION = '0.125.0'
6
6
  end
7
7
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ local_gemfile = ::File.join(::File.dirname(__FILE__), 'Gemfile.local')
8
+ eval_gemfile local_gemfile if ::File.exist?(local_gemfile)
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = Dir['{lib}/**/*']
14
14
 
15
- s.add_dependency 'eac_ruby_utils', '~> 0.74'
16
- s.add_dependency 'eac_templates', '~> 0.1'
15
+ s.add_dependency 'eac_ruby_utils', '~> 0.96'
16
+ s.add_dependency 'eac_templates', '~> 0.3', '>= 0.3.1'
17
17
 
18
- s.add_development_dependency 'eac_ruby_gem_support', '~> 0.3', '>= 0.3.3'
18
+ s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5.1'
19
19
  end
@@ -34,7 +34,7 @@ module EacDocker
34
34
  end
35
35
  end
36
36
 
37
- def volume(left_part, right_part = null)
37
+ def volume(left_part, right_part = nil)
38
38
  immutable_volume(right_part.if_present(left_part) { |v| "#{left_part}:#{v}" })
39
39
  end
40
40
 
@@ -43,8 +43,9 @@ module EacDocker
43
43
  end
44
44
 
45
45
  def run_command_args
46
- run_command_boolean_args + run_command_capabilities_args + run_command_envs_args +
47
- run_command_volumes_args + [image.provide.id] + command_args
46
+ %w[boolean capabilities envs volumes]
47
+ .inject([]) { |a, e| a + send("run_command_#{e}_args") } +
48
+ [image.provide.id] + command_args
48
49
  end
49
50
 
50
51
  def stop
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacDocker
4
- VERSION = '0.4.1'
4
+ VERSION = '0.4.2'
5
5
  end
@@ -8,13 +8,26 @@ module EacRubyUtils
8
8
  module Immutable
9
9
  class ArrayAccessor < ::EacRubyUtils::Immutable::BaseAccessor
10
10
  def apply(klass)
11
+ apply_singular(klass)
12
+ apply_plural(klass)
13
+ end
14
+
15
+ def apply_plural(klass)
11
16
  accessor = self
12
- klass.send(:define_method, name) do |value|
13
- accessor.immutable_value_set(self, value)
17
+ klass.send(:define_method, ::ActiveSupport::Inflector.pluralize(name)) do |*args|
18
+ case args.count
19
+ when 0 then next accessor.immutable_value_get(self)
20
+ when 1 then next accessor.immutable_value_set(self, args.first)
21
+ else
22
+ raise ::ArgumentError, "wrong number of arguments (given #{args.count}, expected 0..1)"
23
+ end
14
24
  end
25
+ end
15
26
 
16
- klass.send(:define_method, ::ActiveSupport::Inflector.pluralize(name)) do
17
- accessor.immutable_value_get(self)
27
+ def apply_singular(klass)
28
+ accessor = self
29
+ klass.send(:define_method, name) do |value|
30
+ accessor.immutable_value_push(self, value)
18
31
  end
19
32
  end
20
33
 
@@ -22,11 +35,15 @@ module EacRubyUtils
22
35
  super || []
23
36
  end
24
37
 
25
- def immutable_value_set(object, value)
38
+ def immutable_value_push(object, value)
26
39
  duplicate_object(object) do |old_value|
27
40
  (old_value || []) + [value]
28
41
  end
29
42
  end
43
+
44
+ def immutable_value_set(object, value)
45
+ duplicate_object(object) { |_old_value| value }
46
+ end
30
47
  end
31
48
  end
32
49
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.95.3'
4
+ VERSION = '0.96.0'
5
5
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ ::RSpec.describe ::EacRubyUtils::Immutable do
4
+ let(:stub_class) do
5
+ the_described_class = described_class
6
+ ::Class.new do
7
+ include the_described_class
8
+
9
+ immutable_accessor :array_attr, type: :array
10
+ end
11
+ end
12
+
13
+ let(:initial_instance) { stub_class.new }
14
+
15
+ it do
16
+ expect(initial_instance.array_attrs).to eq([])
17
+ end
18
+
19
+ context 'when array_attr pushs for' do
20
+ let(:change1_instance) { initial_instance.array_attr('A') }
21
+
22
+ it { expect(change1_instance).to be_a(initial_instance.class) }
23
+ it { expect(change1_instance.object_id).not_to eq(initial_instance.object_id) }
24
+ it { expect(change1_instance.array_attrs).to eq(%w[A]) }
25
+
26
+ context 'when array_attrs sets for' do
27
+ let(:change2_instance) { initial_instance.array_attrs(%w[B]) }
28
+
29
+ it { expect(change2_instance).to be_a(initial_instance.class) }
30
+ it { expect(change2_instance.object_id).not_to eq(change1_instance.object_id) }
31
+ it { expect(change2_instance.array_attrs).to eq(%w[B]) }
32
+ end
33
+ end
34
+ end