avm-tools 0.67.0 → 0.69.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/avm/eac_rails_base0/apache_host.rb +17 -0
- data/lib/avm/eac_rails_base0/deploy.rb +50 -0
- data/lib/avm/eac_rails_base0/instance.rb +14 -0
- data/lib/avm/eac_redmine_base0/deploy.rb +2 -2
- data/lib/avm/eac_redmine_base0/instance.rb +2 -2
- data/lib/avm/eac_webapp_base0/apache_host.rb +103 -0
- data/lib/avm/eac_webapp_base0/deploy.rb +102 -0
- data/lib/avm/eac_webapp_base0/deploy/appended_directories.rb +25 -0
- data/lib/avm/eac_webapp_base0/deploy/file_unit.rb +41 -0
- data/lib/avm/eac_webapp_base0/deploy/git_info.rb +49 -0
- data/lib/avm/eac_webapp_base0/deploy/version.rb +20 -0
- data/lib/avm/eac_webapp_base0/instance.rb +50 -0
- data/lib/avm/eac_webapp_base0/runner/apache_host.rb +39 -0
- data/lib/avm/eac_webapp_base0/runner/data.rb +25 -0
- data/lib/avm/eac_webapp_base0/runner/data/dump.rb +69 -0
- data/lib/avm/eac_webapp_base0/runner/data/load.rb +66 -0
- data/lib/avm/eac_webapp_base0/runner/deploy.rb +59 -0
- data/lib/avm/git/issue/complete/_git_subrepos.rb +1 -0
- data/lib/avm/local_projects/instance.rb +1 -1
- data/lib/avm/projects/stereotypes/git_subrepo/warp.rb +2 -2
- data/lib/avm/projects/stereotypes/rails_application.rb +2 -0
- data/lib/avm/projects/stereotypes/rails_application/local_project_mixin.rb +18 -0
- data/lib/avm/projects/stereotypes/rails_application/update.rb +14 -0
- data/lib/avm/stereotypes/eac_wordpress_base0/apache_host.rb +2 -2
- data/lib/avm/stereotypes/eac_wordpress_base0/deploy.rb +2 -2
- data/lib/avm/stereotypes/eac_wordpress_base0/instance.rb +2 -2
- data/lib/avm/tools/runner/eac_rails_base0.rb +2 -2
- data/lib/avm/tools/runner/eac_rails_base0/apache_host.rb +3 -26
- data/lib/avm/tools/runner/eac_rails_base0/data.rb +2 -2
- data/lib/avm/tools/runner/eac_rails_base0/deploy.rb +3 -3
- data/lib/avm/tools/runner/eac_redmine_base0/data.rb +1 -1
- data/lib/avm/tools/runner/eac_redmine_base0/data/dump.rb +2 -2
- data/lib/avm/tools/runner/eac_redmine_base0/deploy.rb +2 -2
- data/lib/avm/tools/runner/eac_redmine_base0/project_rename.rb +1 -0
- data/lib/avm/tools/runner/eac_wordpress_base0/apache_host.rb +3 -25
- data/lib/avm/tools/runner/eac_wordpress_base0/data.rb +2 -2
- data/lib/avm/tools/runner/eac_wordpress_base0/deploy.rb +2 -2
- data/lib/avm/tools/version.rb +1 -1
- data/lib/eac_launcher/git/sub_warp_base.rb +1 -1
- data/lib/eac_launcher/publish/base.rb +1 -1
- data/template/avm/{stereotypes/eac_rails_base0 → eac_rails_base0}/deploy/config/database.yml.template +0 -0
- data/template/avm/{stereotypes/eac_webapp_base0 → eac_webapp_base0}/apache_host/no_ssl.conf +0 -0
- data/template/avm/self/docker_image/Dockerfile +1 -1
- data/vendor/eac_cli/Gemfile +5 -0
- data/vendor/eac_cli/eac_cli.gemspec +18 -0
- data/vendor/eac_cli/lib/eac_cli.rb +7 -0
- data/vendor/eac_cli/lib/eac_cli/core_ext.rb +4 -0
- data/vendor/eac_cli/lib/eac_cli/default_runner.rb +14 -0
- data/vendor/eac_cli/lib/eac_cli/definition.rb +72 -0
- data/vendor/eac_cli/lib/eac_cli/definition/argument_option.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +26 -0
- data/vendor/eac_cli/lib/eac_cli/definition/boolean_option.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +27 -0
- data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +77 -0
- data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +45 -0
- data/vendor/eac_cli/lib/eac_cli/parser.rb +14 -0
- data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +56 -0
- data/vendor/eac_cli/lib/eac_cli/parser/error.rb +15 -0
- data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +105 -0
- data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +21 -0
- data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +49 -0
- data/vendor/eac_cli/lib/eac_cli/patches.rb +4 -0
- data/vendor/eac_cli/lib/eac_cli/patches/object.rb +5 -0
- data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +24 -0
- data/vendor/eac_cli/lib/eac_cli/runner.rb +87 -0
- data/vendor/eac_cli/lib/eac_cli/runner/context.rb +18 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with.rb +9 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +19 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +26 -0
- data/vendor/eac_cli/lib/eac_cli/version.rb +5 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +70 -0
- data/vendor/eac_cli/spec/rubocop_spec.rb +7 -0
- data/vendor/eac_cli/spec/spec_helper.rb +100 -0
- data/vendor/eac_git/lib/eac_git/version.rb +1 -1
- data/vendor/eac_git/vendor/git-subrepo/lib/git-subrepo +9 -7
- data/vendor/eac_ruby_base0/eac_ruby_base0.gemspec +3 -3
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner.rb +5 -1
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem.rb +10 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem/version_file.rb +6 -5
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/multiple.rb +5 -34
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/multiple/decorated_gem.rb +42 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/multiple/result.rb +25 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/version.rb +1 -1
- data/vendor/eac_ruby_gems_utils/spec/lib/eac_ruby_gems_utils/gem/version_file_spec.rb +14 -0
- data/vendor/eac_ruby_gems_utils/spec/lib/eac_ruby_gems_utils/gem/version_file_spec_files/a_version_file.rb +7 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +4 -4
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner.rb +6 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb +8 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb +18 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/value.rb +3 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string/inflector.rb +9 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/simple_cache.rb +6 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +53 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/inflector_spec.rb +15 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +46 -0
- metadata +61 -18
- data/lib/avm/stereotypes/eac_rails_base0/apache_host.rb +0 -19
- data/lib/avm/stereotypes/eac_rails_base0/deploy.rb +0 -52
- data/lib/avm/stereotypes/eac_rails_base0/instance.rb +0 -16
- data/lib/avm/stereotypes/eac_webapp_base0/apache_host.rb +0 -97
- data/lib/avm/stereotypes/eac_webapp_base0/deploy.rb +0 -104
- data/lib/avm/stereotypes/eac_webapp_base0/deploy/appended_directories.rb +0 -27
- data/lib/avm/stereotypes/eac_webapp_base0/deploy/file_unit.rb +0 -43
- data/lib/avm/stereotypes/eac_webapp_base0/deploy/git_info.rb +0 -51
- data/lib/avm/stereotypes/eac_webapp_base0/deploy/version.rb +0 -22
- data/lib/avm/stereotypes/eac_webapp_base0/instance.rb +0 -52
- data/lib/avm/stereotypes/eac_webapp_base0/runner/data.rb +0 -27
- data/lib/avm/stereotypes/eac_webapp_base0/runner/data/dump.rb +0 -71
- data/lib/avm/stereotypes/eac_webapp_base0/runner/data/load.rb +0 -68
- data/lib/avm/stereotypes/eac_webapp_base0/runner/deploy.rb +0 -61
@@ -12,9 +12,9 @@ Gem::Specification.new do |s|
|
|
12
12
|
|
13
13
|
s.files = Dir['{lib}/**/*']
|
14
14
|
|
15
|
-
s.add_dependency 'eac_cli', '~> 0.
|
16
|
-
s.add_dependency 'eac_ruby_gems_utils', '~> 0.
|
17
|
-
s.add_dependency 'eac_ruby_utils', '~> 0.
|
15
|
+
s.add_dependency 'eac_cli', '~> 0.7'
|
16
|
+
s.add_dependency 'eac_ruby_gems_utils', '~> 0.7', '>= 0.7.2'
|
17
|
+
s.add_dependency 'eac_ruby_utils', '~> 0.46'
|
18
18
|
|
19
19
|
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.1', '>= 0.1.2'
|
20
20
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'eac_ruby_utils/core_ext'
|
4
4
|
require 'eac_ruby_utils/envs'
|
5
|
+
require 'rubygems'
|
5
6
|
|
6
7
|
module EacRubyGemsUtils
|
7
8
|
class Gem
|
@@ -22,6 +23,11 @@ module EacRubyGemsUtils
|
|
22
23
|
::EacRubyGemsUtils::Gem::Command.new(self, %w[bundle] + args).envvar_gemfile
|
23
24
|
end
|
24
25
|
|
26
|
+
# @return A [Pathname] array with relative paths from root listed in gemspec's .file directive.
|
27
|
+
def files
|
28
|
+
gemspec.files.map(&:to_pathname)
|
29
|
+
end
|
30
|
+
|
25
31
|
def gemfile_lock_gem_version(gem_name)
|
26
32
|
gemfile_lock_content.specs.find { |gem| gem.name == gem_name }.if_present(&:version)
|
27
33
|
end
|
@@ -67,6 +73,10 @@ module EacRubyGemsUtils
|
|
67
73
|
gemfile_path.basename_sub { |b| "#{b}.lock" }
|
68
74
|
end
|
69
75
|
|
76
|
+
def gemspec_uncached
|
77
|
+
::Gem::Specification.load(gemspec_path.to_path)
|
78
|
+
end
|
79
|
+
|
70
80
|
def gemspec_path_uncached
|
71
81
|
::Pathname.glob("#{root.to_path}/*#{GEMSPEC_EXTNAME}").first
|
72
82
|
end
|
@@ -10,11 +10,7 @@ module EacRubyGemsUtils
|
|
10
10
|
VERSION_LINE_PATTERN = /\A(\s*)VERSION\s*=\s*[\'\"]([^\'\"]+)[\'\"](\s*)\z/.freeze
|
11
11
|
|
12
12
|
def value
|
13
|
-
path.read.each_line
|
14
|
-
VERSION_LINE_PATTERN.if_match(line.rstrip, false) do |m|
|
15
|
-
::Gem::Version.new(m[2])
|
16
|
-
end
|
17
|
-
end
|
13
|
+
path.read.each_line.lazy.map { |line| line_value(line) }.find { |v| v }
|
18
14
|
end
|
19
15
|
|
20
16
|
def value=(new_value)
|
@@ -23,6 +19,11 @@ module EacRubyGemsUtils
|
|
23
19
|
|
24
20
|
private
|
25
21
|
|
22
|
+
# @return Version found in line, nil otherwise.
|
23
|
+
def line_value(line)
|
24
|
+
VERSION_LINE_PATTERN.if_match(line.rstrip, false) { |m| ::Gem::Version.new(m[2]) }
|
25
|
+
end
|
26
|
+
|
26
27
|
def new_value_content(new_value)
|
27
28
|
path.read.each_line
|
28
29
|
.map { |line| new_value_line(line, new_value) }
|
@@ -7,6 +7,7 @@ require 'eac_ruby_utils/core_ext'
|
|
7
7
|
module EacRubyGemsUtils
|
8
8
|
module Tests
|
9
9
|
class Multiple
|
10
|
+
require_sub __FILE__
|
10
11
|
enable_console_speaker
|
11
12
|
enable_simple_cache
|
12
13
|
common_constructor :gems, :options, default: [{}]
|
@@ -26,14 +27,9 @@ module EacRubyGemsUtils
|
|
26
27
|
decorated_gems.flat_map(&:tests)
|
27
28
|
end
|
28
29
|
|
29
|
-
def
|
30
|
-
infom '
|
31
|
-
decorated_gems.each
|
32
|
-
next unless gem.gemfile_path.exist?
|
33
|
-
|
34
|
-
infov 'Bundle install', gem
|
35
|
-
gem.bundle.execute!
|
36
|
-
end
|
30
|
+
def prepare_all_gems
|
31
|
+
infom 'Preparing all gems...'
|
32
|
+
decorated_gems.each(&:prepare)
|
37
33
|
end
|
38
34
|
|
39
35
|
def decorated_gems_uncached
|
@@ -61,7 +57,7 @@ module EacRubyGemsUtils
|
|
61
57
|
|
62
58
|
def run
|
63
59
|
start_banner
|
64
|
-
|
60
|
+
prepare_all_gems
|
65
61
|
test_all_gems
|
66
62
|
final_results_banner
|
67
63
|
end
|
@@ -76,31 +72,6 @@ module EacRubyGemsUtils
|
|
76
72
|
infov test, Result.new(test.result).tag
|
77
73
|
end
|
78
74
|
end
|
79
|
-
|
80
|
-
class DecoratedGem < ::SimpleDelegator
|
81
|
-
def tests
|
82
|
-
[::EacRubyGemsUtils::Tests::Minitest.new(__getobj__),
|
83
|
-
::EacRubyGemsUtils::Tests::Rspec.new(__getobj__)]
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
class Result
|
88
|
-
common_constructor :result
|
89
|
-
|
90
|
-
COLORS = {
|
91
|
-
::EacRubyGemsUtils::Tests::Base::RESULT_FAILED => :red,
|
92
|
-
::EacRubyGemsUtils::Tests::Base::RESULT_NONEXISTENT => :white,
|
93
|
-
::EacRubyGemsUtils::Tests::Base::RESULT_SUCCESSFUL => :green
|
94
|
-
}.freeze
|
95
|
-
|
96
|
-
def tag
|
97
|
-
result.to_s.send(color)
|
98
|
-
end
|
99
|
-
|
100
|
-
def color
|
101
|
-
COLORS.fetch(result)
|
102
|
-
end
|
103
|
-
end
|
104
75
|
end
|
105
76
|
end
|
106
77
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRubyGemsUtils
|
4
|
+
module Tests
|
5
|
+
class Multiple
|
6
|
+
class DecoratedGem < ::SimpleDelegator
|
7
|
+
enable_console_speaker
|
8
|
+
|
9
|
+
def prepare
|
10
|
+
return unless gemfile_path.exist?
|
11
|
+
|
12
|
+
log('running "bundle install"...')
|
13
|
+
return if bundle('install').execute.fetch(:exit_code).zero?
|
14
|
+
|
15
|
+
if can_remove_gemfile_lock?
|
16
|
+
log('"bundle install" failed, removing Gemfile.lock and trying again...')
|
17
|
+
gemfile_lock_path.unlink if gemfile_lock_path.exist?
|
18
|
+
bundle('install').execute!
|
19
|
+
else
|
20
|
+
raise '"bundle install" failed and the Gemfile.lock is part of gem' \
|
21
|
+
'(Should be changed by developer)'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def tests
|
26
|
+
[::EacRubyGemsUtils::Tests::Minitest.new(__getobj__),
|
27
|
+
::EacRubyGemsUtils::Tests::Rspec.new(__getobj__)]
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def log(message)
|
33
|
+
infov self, message
|
34
|
+
end
|
35
|
+
|
36
|
+
def can_remove_gemfile_lock?
|
37
|
+
!files.include?(gemfile_lock_path.relative_path_from(root))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRubyGemsUtils
|
4
|
+
module Tests
|
5
|
+
class Multiple
|
6
|
+
class Result
|
7
|
+
common_constructor :result
|
8
|
+
|
9
|
+
COLORS = {
|
10
|
+
::EacRubyGemsUtils::Tests::Base::RESULT_FAILED => :red,
|
11
|
+
::EacRubyGemsUtils::Tests::Base::RESULT_NONEXISTENT => :white,
|
12
|
+
::EacRubyGemsUtils::Tests::Base::RESULT_SUCCESSFUL => :green
|
13
|
+
}.freeze
|
14
|
+
|
15
|
+
def tag
|
16
|
+
result.to_s.send(color)
|
17
|
+
end
|
18
|
+
|
19
|
+
def color
|
20
|
+
COLORS.fetch(result)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_gems_utils/gem'
|
4
|
+
|
5
|
+
::RSpec.describe ::EacRubyGemsUtils::Gem::VersionFile do
|
6
|
+
let(:stubs_dir) { ::Pathname.new(__dir__).join('version_file_spec_files') }
|
7
|
+
let(:stub_file) { stubs_dir.join('a_version_file.rb') }
|
8
|
+
let(:instance) { described_class.new(stub_file) }
|
9
|
+
let(:target_version) { ::Gem::Version.new('0.69.1') }
|
10
|
+
|
11
|
+
describe '#value' do
|
12
|
+
it { expect(instance.value).to eq(target_version) }
|
13
|
+
end
|
14
|
+
end
|
@@ -21,10 +21,10 @@ module EacRubyUtils
|
|
21
21
|
|
22
22
|
class Setup
|
23
23
|
include ::EacRubyUtils::SimpleCache
|
24
|
-
attr_reader :a_module, :
|
24
|
+
attr_reader :a_module, :common_concern
|
25
25
|
|
26
|
-
def initialize(
|
27
|
-
@
|
26
|
+
def initialize(common_concern, a_module)
|
27
|
+
@common_concern = common_concern
|
28
28
|
@a_module = a_module
|
29
29
|
end
|
30
30
|
|
@@ -47,7 +47,7 @@ module EacRubyUtils
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def setup_after_callback(base)
|
50
|
-
|
50
|
+
common_concern.after_callback.if_present do |v|
|
51
51
|
base.instance_eval(&v)
|
52
52
|
end
|
53
53
|
end
|
@@ -25,6 +25,8 @@ module EacRubyUtils
|
|
25
25
|
end
|
26
26
|
|
27
27
|
module SubcommandsSupport
|
28
|
+
EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME = :extra_available_subcommands
|
29
|
+
|
28
30
|
def check_subcommands_arg
|
29
31
|
if subcommand_arg_as_list?
|
30
32
|
singleton_class.include(SubcommandsSupport::SubcommandArgAsList)
|
@@ -43,7 +45,7 @@ module EacRubyUtils
|
|
43
45
|
end
|
44
46
|
|
45
47
|
def subcommand
|
46
|
-
@subcommand ||= subcommand_class_name(subcommand_name).constantize.
|
48
|
+
@subcommand ||= subcommand_class_name(subcommand_name).constantize.create(
|
47
49
|
argv: subcommand_args,
|
48
50
|
program_name: subcommand_program,
|
49
51
|
parent: self
|
@@ -77,7 +79,11 @@ module EacRubyUtils
|
|
77
79
|
end
|
78
80
|
|
79
81
|
def available_subcommands
|
80
|
-
(setting_value(:subcommands, false) || auto_available_subcommands)
|
82
|
+
r = ::Set.new(setting_value(:subcommands, false) || auto_available_subcommands)
|
83
|
+
if respond_to?(EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME, true)
|
84
|
+
r += send(EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME)
|
85
|
+
end
|
86
|
+
r.sort
|
81
87
|
end
|
82
88
|
|
83
89
|
def auto_available_subcommands
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRubyUtils
|
4
|
+
class Inflector
|
5
|
+
class << self
|
6
|
+
VARIABLE_NAME_PATTERN = /[_a-z][_a-z0-9]*/i.freeze
|
7
|
+
|
8
|
+
def variableize(string)
|
9
|
+
r = string.gsub(/[^_a-z0-9]/i, '_').gsub(/_+/, '_').gsub(/_\z/, '').gsub(/\A_/, '').downcase
|
10
|
+
m = VARIABLE_NAME_PATTERN.match(r)
|
11
|
+
return r if m
|
12
|
+
|
13
|
+
raise ::ArgumentError, "Invalid variable name \"#{r}\" was generated " \
|
14
|
+
"from string \"#{string}\""
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'eac_ruby_utils/inflector'
|
4
|
+
|
3
5
|
module EacRubyUtils
|
4
6
|
module Listable
|
5
7
|
class Value
|
@@ -16,8 +18,7 @@ module EacRubyUtils
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def constant_name
|
19
|
-
"#{@list.item}_#{@key}"
|
20
|
-
.gsub(/(?:\A_|_\z)/, '').upcase
|
21
|
+
::EacRubyUtils::Inflector.variableize("#{@list.item}_#{@key}").upcase
|
21
22
|
end
|
22
23
|
|
23
24
|
def label
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/hash_with_indifferent_access'
|
4
|
+
require 'active_support/core_ext/object/blank'
|
5
|
+
|
6
|
+
module EacRubyUtils
|
7
|
+
class Struct
|
8
|
+
def initialize(initial_data = {})
|
9
|
+
self.data = ::ActiveSupport::HashWithIndifferentAccess.new(initial_data)
|
10
|
+
end
|
11
|
+
|
12
|
+
def [](key)
|
13
|
+
key, bool = parse_key(key)
|
14
|
+
bool ? self[key].present? : data[key]
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch(key)
|
18
|
+
key, bool = parse_key(key)
|
19
|
+
bool ? fetch(key).present? : data.fetch(key)
|
20
|
+
end
|
21
|
+
|
22
|
+
def method_missing(method_name, *arguments, &block)
|
23
|
+
property_method?(method_name) ? fetch(method_name) : super
|
24
|
+
end
|
25
|
+
|
26
|
+
def respond_to_missing?(method_name, include_private = false)
|
27
|
+
property_method?(method_name) || super
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_h
|
31
|
+
data.dup
|
32
|
+
end
|
33
|
+
|
34
|
+
delegate :to_s, to: :data
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
attr_accessor :data
|
39
|
+
|
40
|
+
def parse_key(key)
|
41
|
+
m = /\A(.+)\?\z/.match(key.to_s)
|
42
|
+
[(m ? m[1] : key.to_s).to_sym, m ? true : false]
|
43
|
+
end
|
44
|
+
|
45
|
+
def property_method?(key)
|
46
|
+
property_methods.include?(key.to_sym)
|
47
|
+
end
|
48
|
+
|
49
|
+
def property_methods
|
50
|
+
data.keys.flat_map { |k| [k.to_sym, "#{k}?".to_sym] }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|