eac_tools 0.7.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +43 -31
- data/lib/eac_tools/version.rb +1 -1
- data/sub/avm/avm.gemspec +1 -0
- data/sub/avm/lib/avm/application_stereotypes/base/by_gem.rb +17 -0
- data/sub/avm/lib/avm/application_stereotypes/base/detection.rb +34 -0
- data/sub/avm/lib/avm/application_stereotypes/base.rb +21 -0
- data/sub/avm/lib/avm/application_stereotypes.rb +9 -0
- data/sub/avm/lib/avm/{instances/application.rb → applications/base.rb} +5 -6
- data/sub/avm/lib/avm/applications.rb +9 -0
- data/sub/avm/lib/avm/docker/image.rb +12 -2
- data/sub/avm/lib/avm/instances/base.rb +7 -2
- data/sub/avm/lib/avm/instances.rb +1 -1
- data/sub/avm/lib/avm/registry/application_stereotypes/build_available.rb +46 -0
- data/sub/avm/lib/avm/registry/application_stereotypes/stereotype_builder.rb +30 -0
- data/sub/avm/lib/avm/registry/application_stereotypes.rb +36 -0
- data/sub/avm/lib/avm/registry/{base.rb → from_gems.rb} +13 -4
- data/sub/avm/lib/avm/registry/instances.rb +16 -0
- data/sub/avm/lib/avm/registry/runners.rb +10 -0
- data/sub/avm/lib/avm/registry/scms.rb +10 -0
- data/sub/avm/lib/avm/registry/sources.rb +10 -0
- data/sub/avm/lib/avm/registry/with_path/cache.rb +31 -0
- data/sub/avm/lib/avm/registry/with_path.rb +33 -7
- data/sub/avm/lib/avm/registry.rb +3 -7
- data/sub/avm/lib/avm/rspec/shared_examples/not_in_avm_registry.rb +1 -1
- data/sub/avm/lib/avm/sources/base/configuration.rb +23 -2
- data/sub/avm/lib/avm/sources/base/instance.rb +2 -2
- data/sub/avm/lib/avm/sources/base/locale.rb +1 -1
- data/sub/avm/lib/avm/sources/base/parent.rb +8 -11
- data/sub/avm/lib/avm/sources/base/subs_paths.rb +1 -1
- data/sub/avm/lib/avm/sources/base/testing.rb +4 -4
- data/sub/avm/lib/avm/sources/base.rb +4 -0
- data/sub/avm/lib/avm/sources/tests/builder.rb +5 -10
- data/sub/avm/lib/avm/version.rb +1 -1
- data/sub/avm/lib/avm/with_application_stereotype.rb +23 -0
- data/sub/avm/lib/avm/with_dynamic_runners.rb +42 -0
- data/sub/{avm-tools/spec/lib/avm/instances/application_spec.rb → avm/spec/lib/avm/applications/base_spec.rb} +3 -3
- data/sub/{avm-tools/spec/lib/avm/instances/application_spec_fixture.yml → avm/spec/lib/avm/applications/base_spec_fixture.yml} +0 -0
- data/sub/{avm-tools → avm}/spec/lib/avm/instances/base_spec.rb +0 -0
- data/sub/{avm-tools → avm}/spec/lib/avm/instances/base_spec_configs_storage.yml +0 -0
- data/sub/avm-eac_generic_base0/avm-eac_generic_base0.gemspec +2 -2
- data/sub/avm-eac_generic_base0/lib/avm/eac_generic_base0/sources/docker/runner.rb +61 -0
- data/sub/avm-eac_generic_base0/lib/avm/eac_generic_base0/sources/docker.rb +13 -0
- data/sub/avm-eac_generic_base0/lib/avm/eac_generic_base0/version.rb +1 -1
- data/sub/avm-eac_rails_base0/Gemfile +3 -0
- data/sub/avm-eac_redmine_base0/avm-eac_redmine_base0.gemspec +1 -0
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/sources/runners/docker.rb +19 -0
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/version.rb +1 -1
- data/sub/avm-eac_redmine_plugin_base0/avm-eac_redmine_plugin_base0.gemspec +1 -1
- data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/sources/base.rb +15 -4
- data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/version.rb +1 -1
- data/sub/avm-eac_ruby_base1/avm-eac_ruby_base1.gemspec +1 -1
- data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/base/bundler.rb +1 -1
- data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/base/rake.rb +14 -0
- data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/version.rb +1 -1
- data/sub/avm-tools/Gemfile +3 -0
- data/sub/avm-tools/avm-tools.gemspec +1 -1
- data/sub/avm-tools/lib/avm/tools/runner/app_src/info.rb +19 -0
- data/sub/avm-tools/lib/avm/tools/runner/application_stereotypes/list.rb +31 -0
- data/sub/avm-tools/lib/avm/tools/runner/application_stereotypes.rb +16 -0
- data/sub/avm-tools/lib/avm/tools/version.rb +1 -1
- data/sub/eac_cli/Gemfile +3 -0
- data/sub/eac_cli/lib/eac_cli/version.rb +1 -1
- data/sub/eac_config/Gemfile +8 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/eac_config.gemspec +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config/entry.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config/entry_path.rb +5 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config/envvars_node/entry.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config/envvars_node.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config/load_nodes_search.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config/load_path.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config/node.rb +6 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config/node_entry.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config/node_uri.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config/old_configs/base.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config/old_configs/file.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config/old_configs.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config/paths_hash/entry_key_error.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config/paths_hash/node.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config/paths_hash/path_search.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config/paths_hash.rb +0 -0
- data/sub/eac_config/lib/eac_config/prefixed_path_node/entry.rb +25 -0
- data/sub/eac_config/lib/eac_config/prefixed_path_node.rb +19 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config/rspec/setup.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config/rspec.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config/version.rb +1 -1
- data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config/yaml_file_node/entry.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config/yaml_file_node.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/spec/lib/eac_config/entry_path_spec.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/spec/lib/eac_config/envvars_node/entry_spec.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/spec/lib/eac_config/envvars_node_spec.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/spec/lib/eac_config/old_configs_spec.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/spec/lib/eac_config/paths_hash_spec.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/spec/lib/eac_config/yaml_file_node_spec.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/spec/lib/eac_config/yaml_file_node_spec_files/storage1.yaml +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/spec/lib/eac_config/yaml_file_node_spec_files/storage1_1.yaml +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/spec/lib/eac_config/yaml_file_node_spec_files/storage1_2/storage1_2_1.yaml +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/spec/lib/eac_config/yaml_file_node_spec_files/storage1_2.yaml +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/spec/rubocop_spec.rb +0 -0
- data/sub/{avm-tools/sub/eac_config → eac_config}/spec/spec_helper.rb +0 -0
- data/sub/eac_docker/Gemfile +8 -0
- data/sub/{avm-tools/sub/eac_docker → eac_docker}/eac_docker.gemspec +3 -3
- data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/container.rb +4 -3
- data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/debug.rb +0 -0
- data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/executables.rb +0 -0
- data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/images/base.rb +0 -0
- data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/images/coded.rb +0 -0
- data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/images/named.rb +0 -0
- data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/images/templatized.rb +0 -0
- data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/images.rb +0 -0
- data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/registry.rb +0 -0
- data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/rspec/setup.rb +0 -0
- data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/rspec.rb +0 -0
- data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker/version.rb +1 -1
- data/sub/{avm-tools/sub/eac_docker → eac_docker}/lib/eac_docker.rb +0 -0
- data/sub/{avm-tools/sub/eac_docker → eac_docker}/spec/lib/eac_docker/executables_spec.rb +0 -0
- data/sub/{avm-tools/sub/eac_docker → eac_docker}/spec/lib/eac_docker/images/coded_spec.rb +0 -0
- data/sub/{avm-tools/sub/eac_docker → eac_docker}/spec/lib/eac_docker/images/coded_spec_files/image1/Dockerfile +0 -0
- data/sub/{avm-tools/sub/eac_docker → eac_docker}/spec/lib/eac_docker/images/templatized_spec.rb +0 -0
- data/sub/{avm-tools/sub/eac_docker → eac_docker}/spec/lib/eac_docker/images/templatized_spec_files/stub_docker_image/Dockerfile +0 -0
- data/sub/{avm-tools/sub/eac_docker → eac_docker}/spec/rubocop_spec.rb +0 -0
- data/sub/{avm-tools/sub/eac_docker → eac_docker}/spec/spec_helper.rb +0 -0
- data/sub/eac_fs/Gemfile +3 -0
- data/sub/eac_fs/lib/eac_fs/version.rb +1 -1
- data/sub/eac_ruby_base0/Gemfile +3 -0
- data/sub/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
- data/sub/eac_ruby_utils/Gemfile +2 -10
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/immutable/array_accessor.rb +22 -5
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/immutable_spec.rb +34 -0
- metadata +101 -87
- data/sub/avm/lib/avm/sources/base/runners.rb +0 -47
- data/sub/avm-tools/Gemfile.lock +0 -296
- data/sub/avm-tools/lib/avm/tools/runner/eac_redmine_base0/dev_docker.rb +0 -17
- data/sub/avm-tools/sub/eac_config/Gemfile +0 -5
- data/sub/avm-tools/sub/eac_docker/Gemfile +0 -5
data/sub/avm-tools/Gemfile
CHANGED
@@ -15,7 +15,7 @@ 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.
|
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
21
|
s.add_dependency 'avm-eac_redmine_base0', '~> 0.5', '>= 0.5.2'
|
@@ -9,11 +9,15 @@ module Avm
|
|
9
9
|
class Info
|
10
10
|
runner_with :help do
|
11
11
|
desc 'Show information about local project instance.'
|
12
|
+
bool_opt '-p', '--parent', 'Show the parent source.'
|
13
|
+
bool_opt '-t', '--tests', 'Show test commands.'
|
12
14
|
end
|
13
15
|
|
14
16
|
def run
|
15
17
|
show_instance
|
16
18
|
show_source
|
19
|
+
show_parent
|
20
|
+
show_test_commands
|
17
21
|
end
|
18
22
|
|
19
23
|
private
|
@@ -23,11 +27,26 @@ module Avm
|
|
23
27
|
infov 'Launcher stereotypes', instance.stereotypes.map(&:label).join(', ')
|
24
28
|
end
|
25
29
|
|
30
|
+
def show_parent
|
31
|
+
return unless parsed.parent?
|
32
|
+
|
33
|
+
infov 'Parent', runner_context.call(:subject).parent
|
34
|
+
end
|
35
|
+
|
26
36
|
def show_source
|
27
37
|
infov 'Stereotype', runner_context.call(:subject).class
|
28
38
|
infov 'SCM', runner_context.call(:subject).scm
|
29
39
|
end
|
30
40
|
|
41
|
+
def show_test_commands
|
42
|
+
return unless parsed.tests?
|
43
|
+
|
44
|
+
infov 'Test commands', runner_context.call(:subject).test_commands.count
|
45
|
+
runner_context.call(:subject).test_commands.each do |name, command|
|
46
|
+
infov " * #{name}", command
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
31
50
|
def instance
|
32
51
|
runner_context.call(:instance)
|
33
52
|
end
|
@@ -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
|
data/sub/eac_cli/Gemfile
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -58,6 +58,12 @@ module EacConfig
|
|
58
58
|
::EacConfig::LoadNodesSearch.new(self).result
|
59
59
|
end
|
60
60
|
|
61
|
+
# @return [EacConfig::PrefixedPathNode]
|
62
|
+
def with_prefix(path_prefix)
|
63
|
+
require 'eac_config/prefixed_path_node'
|
64
|
+
::EacConfig::PrefixedPathNode.new(self, path_prefix)
|
65
|
+
end
|
66
|
+
|
61
67
|
private
|
62
68
|
|
63
69
|
def load_node(node_path)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/sub/{avm-tools/sub/eac_config → eac_config}/lib/eac_config/paths_hash/entry_key_error.rb
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_config/node_entry'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
|
6
|
+
module EacConfig
|
7
|
+
class PrefixedPathNode
|
8
|
+
class Entry < ::EacConfig::NodeEntry
|
9
|
+
enable_simple_cache
|
10
|
+
delegate :found?, :found_node, :secret_value, :value, :value=, :writ_node, to: :full_entry
|
11
|
+
|
12
|
+
# @return [EacConfig::EntryPath]
|
13
|
+
def full_path
|
14
|
+
node.path_prefix + path
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# @return [EacConfig::NodeEntry]
|
20
|
+
def full_entry_uncached
|
21
|
+
node.from_node.entry(full_path)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_config/entry_path'
|
4
|
+
require 'eac_config/paths_hash'
|
5
|
+
require 'eac_ruby_utils/core_ext'
|
6
|
+
|
7
|
+
module EacConfig
|
8
|
+
class PrefixedPathNode
|
9
|
+
require_sub __FILE__
|
10
|
+
include ::EacConfig::Node
|
11
|
+
common_constructor :from_node, :path_prefix do
|
12
|
+
self.path_prefix = ::EacConfig::EntryPath.assert(path_prefix)
|
13
|
+
end
|
14
|
+
|
15
|
+
def entry(path)
|
16
|
+
::EacConfig::Entry.new(self, path)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/sub/{avm-tools/sub/eac_config → eac_config}/spec/lib/eac_config/envvars_node/entry_spec.rb
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -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.
|
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.
|
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 =
|
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
|
-
|
47
|
-
|
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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/sub/{avm-tools/sub/eac_docker → eac_docker}/spec/lib/eac_docker/images/templatized_spec.rb
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/sub/eac_fs/Gemfile
CHANGED
data/sub/eac_ruby_base0/Gemfile
CHANGED
data/sub/eac_ruby_utils/Gemfile
CHANGED
@@ -2,15 +2,7 @@
|
|
2
2
|
|
3
3
|
source 'https://rubygems.org'
|
4
4
|
|
5
|
-
# Declare your gem's dependencies in users_support.gemspec.
|
6
|
-
# Bundler will treat runtime dependencies like base dependencies, and
|
7
|
-
# development dependencies will be added by default to the :development group.
|
8
5
|
gemspec
|
9
6
|
|
10
|
-
|
11
|
-
|
12
|
-
# Git. Remember to move these dependencies to your gemspec before releasing
|
13
|
-
# your gem to rubygems.org.
|
14
|
-
|
15
|
-
# To use a debugger
|
16
|
-
# gem 'byebug', group: [:development, :test]
|
7
|
+
local_gemfile = ::File.join(::File.dirname(__FILE__), 'Gemfile.local')
|
8
|
+
eval_gemfile local_gemfile if ::File.exist?(local_gemfile)
|
@@ -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 |
|
13
|
-
|
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
|
-
|
17
|
-
|
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
|
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
|
@@ -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
|