avm-tools 0.116.0 → 0.117.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/avm/launcher/instances/settings.rb +7 -3
- data/lib/avm/projects/stereotypes.rb +2 -2
- data/lib/avm/ruby/bundler/incompatible_parser/depends_on.rb +1 -1
- data/lib/avm/ruby/bundler/incompatible_parser/gem_conflict.rb +1 -1
- data/lib/avm/ruby/bundler/incompatible_parser/in_gemfile.rb +1 -1
- data/lib/avm/ruby/bundler/incompatible_parser/version_requirement.rb +1 -1
- data/lib/avm/ruby/bundler/incompatible_parser.rb +1 -1
- data/lib/avm/tools/runner/app_src/ruby/bundler/gemfile_lock/git.rb +1 -1
- data/lib/avm/tools/runner/app_src/test.rb +2 -2
- data/lib/avm/tools/runner/app_src/version_bump.rb +4 -9
- data/lib/avm/tools/runner/git/deploy.rb +5 -5
- data/lib/avm/tools/runner/git/dirty_files.rb +1 -1
- data/lib/avm/tools/runner/git/revisions_test.rb +1 -1
- data/lib/avm/tools/runner/ruby/rubocop.rb +2 -2
- data/lib/avm/tools/version.rb +1 -1
- data/sub/avm/avm.gemspec +3 -3
- data/sub/avm/lib/avm/instances/base/auto_values/mailer.rb +2 -2
- data/sub/avm/lib/avm/instances/entry_keys.rb +2 -0
- data/sub/avm/lib/avm/registry/base.rb +2 -2
- data/sub/avm/lib/avm/rspec/shared_examples/not_in_avm_registry.rb +1 -1
- data/sub/avm/lib/avm/scms/base.rb +13 -0
- data/sub/avm/lib/avm/sources/base/configuration.rb +2 -1
- data/sub/avm/lib/avm/sources/base/parent.rb +31 -0
- data/sub/avm/lib/avm/sources/base.rb +4 -6
- data/sub/avm/lib/avm/sources/configuration/{_locale.rb → locale.rb} +5 -3
- data/sub/avm/lib/avm/sources/configuration/rubocop.rb +26 -0
- data/sub/avm/lib/avm/sources/configuration/tests.rb +29 -0
- data/sub/avm/lib/avm/sources/configuration.rb +5 -1
- data/sub/avm/lib/avm/sources/tests/builder.rb +1 -1
- data/sub/avm/lib/avm/version.rb +1 -1
- data/sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/sources/build/file.rb +1 -1
- data/sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/sources/build.rb +2 -2
- data/sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/sources/runner/build.rb +1 -1
- data/sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/sources/runner.rb +2 -2
- data/sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/version.rb +1 -1
- data/sub/avm-eac_generic_base0/avm-eac_generic_base0.gemspec +1 -1
- data/sub/avm-eac_generic_base0/lib/avm/eac_generic_base0/sources/base/version_bump.rb +35 -0
- data/sub/avm-eac_generic_base0/lib/avm/eac_generic_base0/sources/base.rb +4 -1
- data/sub/avm-eac_generic_base0/lib/avm/eac_generic_base0/version.rb +1 -1
- data/sub/avm-eac_generic_base0/locale/en.yaml +6 -0
- data/sub/avm-eac_generic_base0/locale/pt-BR.yaml +6 -0
- data/sub/avm-eac_rails_base1/avm-eac_rails_base1.gemspec +1 -1
- data/sub/avm-eac_rails_base1/lib/avm/eac_rails_base1/version.rb +1 -1
- data/sub/avm-eac_rails_base1/template/avm/eac_rails_base1/systemd_unit/tasks_scheduler_command.sh +1 -1
- data/sub/avm-eac_redmine_base0/avm-eac_redmine_base0.gemspec +1 -1
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/core_update.rb +3 -3
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/docker_image.rb +17 -2
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/version.rb +1 -1
- data/sub/avm-eac_redmine_base0/template/avm/eac_redmine_base0/instances/docker_image/Dockerfile.template +2 -8
- data/sub/avm-eac_redmine_base0/template/avm/eac_redmine_base0/instances/docker_image/Dockerfile_apache_setup +8 -0
- data/sub/avm-eac_redmine_base0/template/avm/eac_redmine_base0/instances/docker_image/start.sh.template +1 -1
- data/sub/avm-eac_ruby_base1/avm-eac_ruby_base1.gemspec +2 -2
- data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubocop/configured.rb +31 -0
- data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubocop/envvar.rb +17 -0
- data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubocop/gemfile.rb +41 -0
- data/{lib/avm/ruby → sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1}/rubocop.rb +2 -2
- data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/base/version_bump.rb +23 -0
- data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/base.rb +11 -0
- data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/tester.rb +1 -1
- data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/update/sub_update.rb +1 -1
- data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/update.rb +0 -1
- data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/version.rb +1 -1
- data/sub/avm-files/avm-files.gemspec +1 -1
- data/sub/avm-files/lib/avm/files/appendable.rb +1 -1
- data/sub/avm-files/lib/avm/files/formatter/formats/ruby.rb +2 -2
- data/sub/avm-files/lib/avm/files/version.rb +1 -1
- data/sub/avm-git/lib/avm/git/scms/git_subrepo.rb +1 -3
- data/sub/avm-git/lib/avm/git/version.rb +1 -1
- data/sub/eac_cli/eac_cli.gemspec +1 -1
- data/sub/eac_cli/lib/eac_cli/old_configs/entry_reader.rb +1 -1
- data/sub/eac_cli/lib/eac_cli/old_configs/read_entry_options.rb +1 -1
- data/sub/eac_cli/lib/eac_cli/parser.rb +2 -2
- data/sub/eac_cli/lib/eac_cli/runner_with/help/builder.rb +1 -1
- data/sub/eac_cli/lib/eac_cli/runner_with/subcommands.rb +4 -4
- data/sub/eac_cli/lib/eac_cli/runner_with_set.rb +2 -2
- data/sub/eac_cli/lib/eac_cli/version.rb +1 -1
- data/sub/eac_config/eac_config.gemspec +1 -1
- data/sub/eac_config/lib/eac_config/entry.rb +1 -1
- data/sub/eac_config/lib/eac_config/envvars_node/entry.rb +1 -1
- data/sub/eac_config/lib/eac_config/paths_hash/node.rb +1 -1
- data/sub/eac_config/lib/eac_config/version.rb +1 -1
- data/sub/eac_fs/eac_fs.gemspec +1 -1
- data/sub/eac_fs/lib/eac_fs/version.rb +1 -1
- data/sub/eac_git/eac_git.gemspec +1 -1
- data/sub/eac_git/lib/eac_git/local/remote.rb +2 -2
- data/sub/eac_git/lib/eac_git/local.rb +1 -1
- data/sub/eac_git/lib/eac_git/version.rb +1 -1
- data/sub/eac_rest/eac_rest.gemspec +1 -1
- data/sub/eac_rest/lib/eac_rest/api.rb +14 -3
- data/sub/eac_rest/lib/eac_rest/request.rb +22 -1
- data/sub/eac_rest/lib/eac_rest/response.rb +41 -1
- data/sub/eac_rest/lib/eac_rest/version.rb +1 -1
- data/sub/eac_ruby_base0/eac_ruby_base0.gemspec +1 -1
- data/sub/eac_ruby_base0/lib/eac_ruby_base0/application.rb +2 -2
- data/sub/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
- data/sub/eac_ruby_gems_utils/eac_ruby_gems_utils.gemspec +1 -1
- data/sub/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem/version_file.rb +2 -2
- data/sub/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/version.rb +1 -1
- data/sub/eac_ruby_utils/eac_ruby_utils.gemspec +1 -1
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/core_ext.rb +1 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/custom_format.rb +1 -1
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/gems_registry/gem.rb +1 -1
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/gems_registry.rb +1 -1
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb +1 -1
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/listable/list.rb +16 -4
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/listable/value.rb +12 -2
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/local_time_zone.rb +1 -1
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_all_gems.rb +4 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_gem.rb +47 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/locales/module_i18n_translate.rb +74 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/locales.rb +9 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/method_class.rb +35 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/i18n_translate.rb +2 -25
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/method_class.rb +9 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +6 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub.rb +86 -33
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/ruby/on_clean_environment.rb +1 -1
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/temp/{temp_spec.rb → directory_spec.rb} +0 -0
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/temp_spec.rb +4 -4
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/listable_spec.rb +169 -106
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/method_class_spec.rb +46 -0
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb +52 -17
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/listable_spec.rb +5 -3
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/method_class_spec.rb +20 -0
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/simple_cache_spec.rb +5 -3
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec.rb +3 -3
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/settings_provider_spec.rb +21 -18
- data/sub/eac_ruby_utils/spec/locales/pt-BR.yml +3 -0
- data/sub/eac_templates/eac_templates.gemspec +1 -1
- data/sub/eac_templates/lib/eac_templates/directory.rb +1 -1
- data/sub/eac_templates/lib/eac_templates/version.rb +1 -1
- metadata +42 -20
- data/lib/avm/projects/stereotypes/rails_application/update.rb +0 -14
- data/lib/avm/projects/stereotypes/ruby_gem/version_bump.rb +0 -60
- data/lib/avm/ruby/rubocop/_configured.rb +0 -29
- data/lib/avm/ruby/rubocop/_envvar.rb +0 -15
- data/lib/avm/ruby/rubocop/_gemfile.rb +0 -39
- data/sub/avm/lib/avm/sources/configuration/_rubocop.rb +0 -24
- data/sub/avm/lib/avm/sources/configuration/_tests.rb +0 -27
- data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/patches/i18n.rb +0 -7
- data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/patches.rb +0 -4
@@ -8,11 +8,14 @@ module EacRest
|
|
8
8
|
# * self.issue_get_url_suffix(provider_issue_id)
|
9
9
|
class Api
|
10
10
|
require_sub __FILE__, include_modules: true
|
11
|
-
|
11
|
+
attr_accessor :ssl_verify
|
12
|
+
common_constructor :root_url, :username, :password, default: [nil, nil] do
|
13
|
+
self.ssl_verify = true
|
14
|
+
end
|
12
15
|
|
13
16
|
def request(service_url_suffix, headers = {}, &body_data_proc)
|
14
17
|
r = ::EacRest::Request.new(build_service_url(service_url_suffix),
|
15
|
-
body_data_proc)
|
18
|
+
body_data_proc).ssl_verify(ssl_verify)
|
16
19
|
headers.each { |name, value| r = r.header(name, value) }
|
17
20
|
r = r.autenticate(username, password) if username.present?
|
18
21
|
r
|
@@ -28,12 +31,20 @@ module EacRest
|
|
28
31
|
|
29
32
|
# @return [Addressable::URI]
|
30
33
|
def build_service_url(suffix)
|
31
|
-
|
34
|
+
r = ::Addressable::URI.parse(suffix)
|
35
|
+
return r if r.scheme.present?
|
36
|
+
|
37
|
+
s = build_service_url_suffix(suffix)
|
32
38
|
r = ::Addressable::URI.parse(root_url)
|
33
39
|
r.path += s.path
|
34
40
|
r.query_values = r.query_values(::Array).if_present([]) +
|
35
41
|
s.query_values(::Array).if_present([])
|
36
42
|
r
|
37
43
|
end
|
44
|
+
|
45
|
+
# @return [Addressable::URI]
|
46
|
+
def build_service_url_suffix(suffix)
|
47
|
+
::Addressable::URI.parse(suffix)
|
48
|
+
end
|
38
49
|
end
|
39
50
|
end
|
@@ -7,11 +7,13 @@ require 'ostruct'
|
|
7
7
|
|
8
8
|
module EacRest
|
9
9
|
class Request
|
10
|
+
BOOLEAN_MODIFIERS = %w[ssl_verify ssl_verify_peer ssl_verify_host].freeze
|
10
11
|
COMMON_MODIFIERS = %w[auth body_data verb].freeze
|
11
12
|
HASH_MODIFIERS = %w[header].freeze
|
12
|
-
MODIFIERS = COMMON_MODIFIERS + HASH_MODIFIERS.map(&:pluralize)
|
13
|
+
MODIFIERS = COMMON_MODIFIERS + BOOLEAN_MODIFIERS + HASH_MODIFIERS.map(&:pluralize)
|
13
14
|
|
14
15
|
enable_immutable
|
16
|
+
immutable_accessor(*BOOLEAN_MODIFIERS, type: :boolean)
|
15
17
|
immutable_accessor(*COMMON_MODIFIERS, type: :common)
|
16
18
|
immutable_accessor(*HASH_MODIFIERS, type: :hash)
|
17
19
|
|
@@ -56,6 +58,25 @@ module EacRest
|
|
56
58
|
curl.headers.merge!(headers)
|
57
59
|
end
|
58
60
|
|
61
|
+
def build_curl_ssl_verify(curl)
|
62
|
+
return if ssl_verify?.nil?
|
63
|
+
|
64
|
+
curl.ssl_verify_host = ssl_verify?
|
65
|
+
curl.ssl_verify_peer = ssl_verify?
|
66
|
+
end
|
67
|
+
|
68
|
+
def build_curl_ssl_verify_peer(curl)
|
69
|
+
return if ssl_verify_peer?.nil?
|
70
|
+
|
71
|
+
curl.ssl_verify_peer = ssl_verify_peer?
|
72
|
+
end
|
73
|
+
|
74
|
+
def build_curl_ssl_verify_host(curl)
|
75
|
+
return if ssl_verify_host?.nil?
|
76
|
+
|
77
|
+
curl.ssl_verify_peer = ssl_verify_host?
|
78
|
+
end
|
79
|
+
|
59
80
|
def build_curl_verb(curl)
|
60
81
|
curl.set(
|
61
82
|
:customrequest,
|
@@ -6,6 +6,18 @@ require 'json'
|
|
6
6
|
|
7
7
|
module EacRest
|
8
8
|
class Response < ::StandardError
|
9
|
+
HEADER_LINE_PARSER = /\A([^:]+):(.*)\z/.to_parser do |m|
|
10
|
+
[m[1].strip, m[2].strip]
|
11
|
+
end
|
12
|
+
|
13
|
+
# https://www.w3.org/wiki/LinkHeader
|
14
|
+
LINKS_HEADER_NAME = 'Link'
|
15
|
+
|
16
|
+
# https://www.w3.org/wiki/LinkHeader
|
17
|
+
LINK_PARSER = /\A\<(.+)\>\s*;\s*rel\s*=\s*\"(.*)\"\z/.to_parser do |m|
|
18
|
+
[m[2], m[1]]
|
19
|
+
end
|
20
|
+
|
9
21
|
common_constructor :curl, :body_data_proc
|
10
22
|
|
11
23
|
def body_data
|
@@ -23,7 +35,7 @@ module EacRest
|
|
23
35
|
body_data
|
24
36
|
end
|
25
37
|
|
26
|
-
delegate :body_str,
|
38
|
+
delegate :body_str, to: :performed_curl
|
27
39
|
|
28
40
|
def body_str_or_raise
|
29
41
|
raise_unless_200
|
@@ -31,6 +43,26 @@ module EacRest
|
|
31
43
|
body_str
|
32
44
|
end
|
33
45
|
|
46
|
+
def header(name)
|
47
|
+
hash_search(headers, name)
|
48
|
+
end
|
49
|
+
|
50
|
+
def headers
|
51
|
+
performed_curl.header_str.each_line.map(&:strip)[1..-1].reject(&:blank?)
|
52
|
+
.map { |header_line| HEADER_LINE_PARSER.parse!(header_line) }
|
53
|
+
.to_h
|
54
|
+
end
|
55
|
+
|
56
|
+
def link(rel)
|
57
|
+
hash_search(links, rel)
|
58
|
+
end
|
59
|
+
|
60
|
+
def links
|
61
|
+
header(LINKS_HEADER_NAME).if_present({}) do |v|
|
62
|
+
v.split(',').map { |w| LINK_PARSER.parse!(w.strip) }.to_h
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
34
66
|
def raise_unless_200
|
35
67
|
return nil if status == 200
|
36
68
|
|
@@ -57,6 +89,14 @@ module EacRest
|
|
57
89
|
Hash.from_xml(body_str)
|
58
90
|
end
|
59
91
|
|
92
|
+
def hash_search(hash, key)
|
93
|
+
key = key.to_s.downcase
|
94
|
+
hash.each do |k, v|
|
95
|
+
return v if k.to_s.downcase == key
|
96
|
+
end
|
97
|
+
nil
|
98
|
+
end
|
99
|
+
|
60
100
|
def perform
|
61
101
|
@perform ||= begin
|
62
102
|
curl.perform || raise("CURL perform failed for #{url}")
|
@@ -17,5 +17,5 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.add_dependency 'eac_ruby_gems_utils', '~> 0.9', '~> 0.9.6'
|
18
18
|
s.add_dependency 'eac_ruby_utils', '~> 0.70'
|
19
19
|
|
20
|
-
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.
|
20
|
+
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5.1'
|
21
21
|
end
|
@@ -23,7 +23,7 @@ module EacRubyBase0
|
|
23
23
|
delegate :version, to: :self_gem
|
24
24
|
|
25
25
|
def all_gems
|
26
|
-
|
26
|
+
sub_gems + [self_gem]
|
27
27
|
end
|
28
28
|
|
29
29
|
# @return [EacCli::Config]
|
@@ -75,7 +75,7 @@ CODE
|
|
75
75
|
::EacRubyGemsUtils::Gem.new(gemspec_dir)
|
76
76
|
end
|
77
77
|
|
78
|
-
def
|
78
|
+
def sub_gems_uncached
|
79
79
|
r = []
|
80
80
|
vendor_dir.children.each do |c|
|
81
81
|
vgem = ::EacRubyGemsUtils::Gem.new(c)
|
@@ -19,5 +19,5 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.add_dependency 'addressable', '~> 2.6'
|
20
20
|
s.add_dependency 'filesize'
|
21
21
|
s.add_dependency 'net-ssh', '~> 4.2'
|
22
|
-
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.
|
22
|
+
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5.1'
|
23
23
|
end
|
@@ -16,7 +16,7 @@ module EacRubyUtils
|
|
16
16
|
# @raise [ArgumentError]
|
17
17
|
def variableize(string, validate = true)
|
18
18
|
r = ::ActiveSupport::Inflector.transliterate(string).gsub(/[^_a-z0-9]/i, '_')
|
19
|
-
|
19
|
+
.gsub(/_+/, '_').gsub(/_\z/, '').gsub(/\A_/, '').downcase
|
20
20
|
m = VARIABLE_NAME_PATTERN.match(r)
|
21
21
|
return r if m
|
22
22
|
return nil unless validate
|
@@ -1,8 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'eac_ruby_utils/listable/value'
|
4
|
+
|
3
5
|
module EacRubyUtils
|
4
6
|
module Listable
|
5
7
|
class List
|
8
|
+
BLANK_VALUE = nil
|
9
|
+
BLANK_KEY = :__blank
|
10
|
+
|
6
11
|
attr_reader :item
|
7
12
|
|
8
13
|
def initialize(lists, item, labels)
|
@@ -12,6 +17,10 @@ module EacRubyUtils
|
|
12
17
|
apply_constants
|
13
18
|
end
|
14
19
|
|
20
|
+
def blank_value
|
21
|
+
@blank_value ||= ::EacRubyUtils::Listable::Value.new(self, BLANK_VALUE, BLANK_KEY, false)
|
22
|
+
end
|
23
|
+
|
15
24
|
def each_value(&block)
|
16
25
|
values.each(&block)
|
17
26
|
end
|
@@ -34,7 +43,7 @@ module EacRubyUtils
|
|
34
43
|
end
|
35
44
|
|
36
45
|
def hash_keys_validate!(hash, error_class = ::StandardError)
|
37
|
-
hash.
|
46
|
+
hash.each_key { |key| value_validate!(key, error_class) }
|
38
47
|
hash
|
39
48
|
end
|
40
49
|
|
@@ -42,11 +51,14 @@ module EacRubyUtils
|
|
42
51
|
"eac_ruby_utils.listable.#{class_i18n_key}.#{item}"
|
43
52
|
end
|
44
53
|
|
54
|
+
# @return [EacRubyUtils::Listable::Value, nil]
|
45
55
|
def instance_value(instance)
|
46
56
|
v = instance.send(item)
|
57
|
+
return blank_value if v.blank?
|
47
58
|
return @values[v] if @values.key?(v)
|
48
59
|
|
49
|
-
raise "List value unkown: #{v} (Source: #{@lists.source}, Item: #{item}
|
60
|
+
raise "List value unkown: \"#{v}\" (Source: #{@lists.source}, Item: #{item}, Instance: " \
|
61
|
+
"#{instance.to_debug}, Values: #{@values.keys})"
|
50
62
|
end
|
51
63
|
|
52
64
|
def value_valid?(value)
|
@@ -70,7 +82,7 @@ module EacRubyUtils
|
|
70
82
|
end
|
71
83
|
|
72
84
|
def find_list_by_method(method)
|
73
|
-
@values.
|
85
|
+
@values.each_value do |v|
|
74
86
|
return v if method.to_s == "value_#{v.key}"
|
75
87
|
end
|
76
88
|
nil
|
@@ -81,7 +93,7 @@ module EacRubyUtils
|
|
81
93
|
end
|
82
94
|
|
83
95
|
def apply_constants
|
84
|
-
@values.
|
96
|
+
@values.each_value do |v|
|
85
97
|
@lists.source.const_set(v.constant_name, v.value)
|
86
98
|
end
|
87
99
|
end
|
@@ -7,10 +7,11 @@ module EacRubyUtils
|
|
7
7
|
class Value
|
8
8
|
attr_reader :value, :key
|
9
9
|
|
10
|
-
def initialize(list, value, key)
|
10
|
+
def initialize(list, value, key, translation_required = true)
|
11
11
|
@list = list
|
12
12
|
@value = value
|
13
13
|
@key = key
|
14
|
+
@translation_required = translation_required
|
14
15
|
end
|
15
16
|
|
16
17
|
def to_s
|
@@ -29,10 +30,19 @@ module EacRubyUtils
|
|
29
30
|
translate('description')
|
30
31
|
end
|
31
32
|
|
33
|
+
def translation_required?
|
34
|
+
@translation_required
|
35
|
+
end
|
36
|
+
|
32
37
|
private
|
33
38
|
|
34
39
|
def translate(translate_key)
|
35
|
-
|
40
|
+
full_translate_key = "#{@list.i18n_key}.#{@key}.#{translate_key}"
|
41
|
+
if !::I18n.exists?(full_translate_key) && !translation_required?
|
42
|
+
''
|
43
|
+
else
|
44
|
+
::I18n.t(full_translate_key)
|
45
|
+
end
|
36
46
|
end
|
37
47
|
end
|
38
48
|
end
|
@@ -36,7 +36,7 @@ module EacRubyUtils
|
|
36
36
|
return nil unless executable.exist?
|
37
37
|
|
38
38
|
TIMEDATECTL_TIMEZONE_LINE_PATTERN.if_match(executable.command.execute!) { |m| m[1] }
|
39
|
-
|
39
|
+
.if_present { |v| ::ActiveSupport::TimeZone[v] }
|
40
40
|
end
|
41
41
|
|
42
42
|
# @return [ActiveSupport::TimeZone]
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'i18n'
|
4
|
+
require 'eac_ruby_utils/patches/class/common_constructor'
|
5
|
+
require 'eac_ruby_utils/patches/object/to_pathname'
|
6
|
+
|
7
|
+
module EacRubyUtils
|
8
|
+
module Locales
|
9
|
+
class FromGem
|
10
|
+
class << self
|
11
|
+
def include_all(i18n_obj = nil)
|
12
|
+
::Gem::Specification.each { |gemspec| new(gemspec, i18n_obj).include }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
LOCALES_DIR_SUBPATH = 'locale'
|
17
|
+
LOCALES_FILES_GLOB_PATTERNS = %w[*.yaml *.yml].freeze
|
18
|
+
|
19
|
+
common_constructor :gemspec, :i18n_obj, default: [nil] do
|
20
|
+
self.i18n_obj ||= ::I18n
|
21
|
+
end
|
22
|
+
|
23
|
+
# @return [Boolean]
|
24
|
+
delegate :exist?, to: :path
|
25
|
+
|
26
|
+
# @return [Pathname, nil]
|
27
|
+
def include
|
28
|
+
return nil unless exist?
|
29
|
+
|
30
|
+
::I18n.load_path += paths_to_load.map(&:to_path)
|
31
|
+
path
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [Pathname]
|
35
|
+
def path
|
36
|
+
gemspec.gem_dir.to_pathname.join(LOCALES_DIR_SUBPATH)
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [Pathname]
|
40
|
+
def paths_to_load
|
41
|
+
return [] unless exist?
|
42
|
+
|
43
|
+
LOCALES_FILES_GLOB_PATTERNS.inject([]) { |a, e| a + path.glob(e) }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/string/inflections'
|
4
|
+
require 'eac_ruby_utils/common_constructor'
|
5
|
+
require 'i18n'
|
6
|
+
|
7
|
+
module EacRubyUtils
|
8
|
+
module Locales
|
9
|
+
class ModuleI18nTranslate
|
10
|
+
TRANSLATE_LOCALE_KEY = :__locale
|
11
|
+
|
12
|
+
common_constructor :the_module, :entry_suffix, :values, default: [{}]
|
13
|
+
|
14
|
+
def ancestor_i18n_translate(ancestor)
|
15
|
+
t = self.class.new(ancestor, entry_suffix, values)
|
16
|
+
t.exists? ? t.i18n_translate : nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def ancestors_i18n_translate
|
20
|
+
the_module.ancestors.lazy.map { |v| ancestor_i18n_translate(v) }.find(&:present?)
|
21
|
+
end
|
22
|
+
|
23
|
+
def exists?
|
24
|
+
::I18n.exists?(i18n_key)
|
25
|
+
end
|
26
|
+
|
27
|
+
def i18n_key
|
28
|
+
"#{module_entry_prefix}.#{entry_suffix}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def i18n_options
|
32
|
+
values.except(TRANSLATE_LOCALE_KEY)
|
33
|
+
end
|
34
|
+
|
35
|
+
def i18n_translate
|
36
|
+
::I18n.translate(i18n_key, i18n_options)
|
37
|
+
end
|
38
|
+
|
39
|
+
def locale
|
40
|
+
values[TRANSLATE_LOCALE_KEY]
|
41
|
+
end
|
42
|
+
|
43
|
+
def module_entry_prefix
|
44
|
+
the_module.name.underscore.gsub('/', '.')
|
45
|
+
end
|
46
|
+
|
47
|
+
def on_locale(&block)
|
48
|
+
if locale.present?
|
49
|
+
on_present_locale(&block)
|
50
|
+
else
|
51
|
+
block.call
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def result
|
56
|
+
on_locale do
|
57
|
+
ancestors_i18n_translate || i18n_translate
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def on_present_locale(&block)
|
64
|
+
old_locale = ::I18n.locale
|
65
|
+
begin
|
66
|
+
::I18n.locale = locale
|
67
|
+
block.call
|
68
|
+
ensure
|
69
|
+
::I18n.locale = old_locale
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/module/introspection'
|
4
|
+
require 'eac_ruby_utils/patches/class/common_constructor'
|
5
|
+
require 'eac_ruby_utils/patches/module/common_concern'
|
6
|
+
require 'eac_ruby_utils/patches/string/inflector'
|
7
|
+
|
8
|
+
module EacRubyUtils
|
9
|
+
module MethodClass
|
10
|
+
common_concern do
|
11
|
+
::EacRubyUtils::MethodClass::Setup.new(self)
|
12
|
+
end
|
13
|
+
|
14
|
+
class Setup
|
15
|
+
common_constructor :method_class do
|
16
|
+
perform
|
17
|
+
end
|
18
|
+
|
19
|
+
def perform
|
20
|
+
the_setup = self
|
21
|
+
sender_module.define_method(method_name) do |*args, &block|
|
22
|
+
the_setup.method_class.new(self, *args, &block).result
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def method_name
|
27
|
+
method_class.name.demodulize.underscore.variableize
|
28
|
+
end
|
29
|
+
|
30
|
+
def sender_module
|
31
|
+
method_class.module_parent
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,32 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'i18n'
|
3
|
+
require 'eac_ruby_utils/locales/module_i18n_translate'
|
5
4
|
|
6
5
|
class Module
|
7
|
-
TRANSLATE_LOCALE_KEY = :__locale
|
8
|
-
|
9
6
|
def i18n_translate(entry_suffix, values = {})
|
10
|
-
|
11
|
-
::I18n.translate(i18n_translate_entry_full(entry_suffix), values)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def i18n_translate_entry_full(entry_suffix)
|
16
|
-
"#{i18n_translate_entry_self_prefix}.#{entry_suffix}"
|
17
|
-
end
|
18
|
-
|
19
|
-
def i18n_translate_entry_self_prefix
|
20
|
-
name.underscore.gsub('/', '.')
|
21
|
-
end
|
22
|
-
|
23
|
-
def on_i18n_locale(locale)
|
24
|
-
old_locale = ::I18n.locale
|
25
|
-
begin
|
26
|
-
::I18n.locale = locale
|
27
|
-
yield
|
28
|
-
ensure
|
29
|
-
::I18n.locale = old_locale
|
30
|
-
end
|
7
|
+
::EacRubyUtils::Locales::ModuleI18nTranslate.new(self, entry_suffix, values).result
|
31
8
|
end
|
32
9
|
end
|