avm-tools 0.116.2 → 0.117.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/ruby/bundler/incompatible_parser/in_gemfile.rb +0 -2
  3. data/lib/avm/tools/runner/app_src/version_bump.rb +4 -9
  4. data/lib/avm/tools/version.rb +1 -1
  5. data/sub/avm/avm.gemspec +1 -1
  6. data/sub/avm/lib/avm/scms/base.rb +13 -0
  7. data/sub/avm/lib/avm/sources/base/configuration.rb +2 -1
  8. data/sub/avm/lib/avm/sources/base/parent.rb +31 -0
  9. data/sub/avm/lib/avm/sources/base.rb +4 -6
  10. data/sub/avm/lib/avm/sources/configuration/{_locale.rb → locale.rb} +5 -3
  11. data/sub/avm/lib/avm/sources/configuration/rubocop.rb +26 -0
  12. data/sub/avm/lib/avm/sources/configuration/tests.rb +29 -0
  13. data/sub/avm/lib/avm/sources/configuration.rb +5 -1
  14. data/sub/avm/lib/avm/version.rb +1 -1
  15. data/sub/avm-eac_generic_base0/avm-eac_generic_base0.gemspec +1 -1
  16. data/sub/avm-eac_generic_base0/lib/avm/eac_generic_base0/sources/base/version_bump.rb +35 -0
  17. data/sub/avm-eac_generic_base0/lib/avm/eac_generic_base0/sources/base.rb +4 -1
  18. data/sub/avm-eac_generic_base0/lib/avm/eac_generic_base0/version.rb +1 -1
  19. data/sub/avm-eac_generic_base0/locale/en.yaml +6 -0
  20. data/sub/avm-eac_generic_base0/locale/pt-BR.yaml +6 -0
  21. data/sub/avm-eac_ruby_base1/avm-eac_ruby_base1.gemspec +1 -1
  22. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/bundler/gemfile/add_or_replace_gem_line.rb +56 -0
  23. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/bundler/gemfile/dependency.rb +19 -0
  24. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/bundler/gemfile.rb +34 -0
  25. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/bundler.rb +11 -0
  26. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/base/version_bump.rb +23 -0
  27. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/base.rb +11 -0
  28. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/update.rb +0 -1
  29. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/version.rb +1 -1
  30. data/sub/avm-git/lib/avm/git/scms/git_subrepo.rb +1 -3
  31. data/sub/avm-git/lib/avm/git/version.rb +1 -1
  32. data/sub/eac_cli/eac_cli.gemspec +1 -1
  33. data/sub/eac_cli/lib/eac_cli/definition.rb +0 -4
  34. data/sub/eac_cli/lib/eac_cli/parser/alternative/short_options.rb +1 -1
  35. data/sub/eac_cli/lib/eac_cli/runner/after_class_methods.rb +9 -22
  36. data/sub/eac_cli/lib/eac_cli/runner/class_runner.rb +50 -0
  37. data/sub/eac_cli/lib/eac_cli/runner/instance_methods.rb +0 -9
  38. data/sub/eac_cli/lib/eac_cli/runner_with/help/builder/alternative.rb +12 -5
  39. data/sub/eac_cli/lib/eac_cli/runner_with/help/builder.rb +15 -6
  40. data/sub/eac_cli/lib/eac_cli/runner_with/help.rb +2 -2
  41. data/sub/eac_cli/lib/eac_cli/runner_with/subcommands.rb +1 -1
  42. data/sub/eac_cli/lib/eac_cli/version.rb +1 -1
  43. data/sub/eac_cli/spec/lib/eac_cli/runner_with/help_spec.rb +26 -17
  44. data/sub/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +4 -1
  45. data/sub/eac_ruby_base0/eac_ruby_base0.gemspec +2 -2
  46. data/sub/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
  47. data/sub/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb +2 -2
  48. data/sub/eac_ruby_utils/lib/eac_ruby_utils/core_ext.rb +1 -0
  49. data/sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_all_gems.rb +4 -0
  50. data/sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_gem.rb +47 -0
  51. data/sub/eac_ruby_utils/lib/eac_ruby_utils/locales/module_i18n_translate.rb +74 -0
  52. data/sub/eac_ruby_utils/lib/eac_ruby_utils/locales.rb +9 -0
  53. data/sub/eac_ruby_utils/lib/eac_ruby_utils/method_class.rb +35 -0
  54. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/i18n_translate.rb +2 -25
  55. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/method_class.rb +9 -0
  56. data/sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub.rb +86 -33
  57. data/sub/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  58. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/method_class_spec.rb +46 -0
  59. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/method_class_spec.rb +20 -0
  60. metadata +31 -12
  61. data/lib/avm/projects/stereotypes/rails_application/update.rb +0 -14
  62. data/lib/avm/projects/stereotypes/ruby_gem/version_bump.rb +0 -60
  63. data/sub/avm/lib/avm/sources/configuration/_rubocop.rb +0 -24
  64. data/sub/avm/lib/avm/sources/configuration/_tests.rb +0 -27
  65. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/patches/i18n.rb +0 -7
  66. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/patches.rb +0 -4
  67. data/sub/eac_cli/lib/eac_cli/definition/help_formatter.rb +0 -77
@@ -1,23 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_cli/speaker'
4
- require 'eac_ruby_utils/speaker'
3
+ require 'eac_cli/definition'
4
+ require 'eac_cli/runner/class_runner'
5
5
 
6
6
  module EacCli
7
7
  module Runner
8
8
  module AfterClassMethods
9
+ # @return [EacCli::Runner::ClassRunner]
10
+ def class_runner(runner_context_args)
11
+ ::EacCli::Runner::ClassRunner.new(self, runner_context_args)
12
+ end
13
+
9
14
  def create(*runner_context_args)
10
- r = new
11
- r.runner_context = ::EacCli::Runner::Context.new(r, *runner_context_args)
12
- r
15
+ class_runner(runner_context_args).create
13
16
  end
14
17
 
15
18
  def run(*runner_context_args)
16
- on_asserted_speaker do
17
- r = create(*runner_context_args)
18
- r.run_run
19
- r
20
- end
19
+ class_runner(runner_context_args).run
21
20
  end
22
21
 
23
22
  def runner_definition(&block)
@@ -29,18 +28,6 @@ module EacCli
29
28
  def super_runner_definition
30
29
  superclass.try(:runner_definition).if_present(&:dup) || ::EacCli::Definition.new
31
30
  end
32
-
33
- private
34
-
35
- def on_asserted_speaker
36
- if ::EacRubyUtils::Speaker.context.optional_current
37
- yield
38
- else
39
- ::EacRubyUtils::Speaker.context.on(::EacCli::Speaker.new) do
40
- yield
41
- end
42
- end
43
- end
44
31
  end
45
32
  end
46
33
  end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/speaker'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'eac_ruby_utils/speaker'
6
+
7
+ module EacCli
8
+ module Runner
9
+ class ClassRunner
10
+ PARSER_ERROR_EXIT_CODE = 1
11
+
12
+ common_constructor :klass, :context_args
13
+
14
+ def create
15
+ r = klass.new
16
+ r.runner_context = ::EacCli::Runner::Context.new(r, *context_args)
17
+ r
18
+ end
19
+
20
+ def run
21
+ on_asserted_speaker do
22
+ r = create
23
+ begin
24
+ r.run_run
25
+ rescue ::EacCli::Parser::Error => e
26
+ run_parser_error(r, e)
27
+ end
28
+ r
29
+ end
30
+ end
31
+
32
+ def run_parser_error(runner_instance, error)
33
+ $stderr.write("#{runner_instance.program_name}: #{error}\n")
34
+ ::Kernel.exit(PARSER_ERROR_EXIT_CODE)
35
+ end
36
+
37
+ private
38
+
39
+ def on_asserted_speaker
40
+ if ::EacRubyUtils::Speaker.context.optional_current
41
+ yield
42
+ else
43
+ ::EacRubyUtils::Speaker.context.on(::EacCli::Speaker.new) do
44
+ yield
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -3,22 +3,13 @@
3
3
  module EacCli
4
4
  module Runner
5
5
  module InstanceMethods
6
- PARSER_ERROR_EXIT_CODE = 1
7
-
8
6
  def run_run
9
7
  parsed
10
8
  run_callbacks(:run) { run }
11
- rescue ::EacCli::Parser::Error => e
12
- run_parser_error(e)
13
9
  rescue ::EacCli::Runner::Exit # rubocop:disable Lint/SuppressedException
14
10
  # Do nothing
15
11
  end
16
12
 
17
- def run_parser_error(error)
18
- $stderr.write("#{program_name}: #{error}\n")
19
- ::Kernel.exit(PARSER_ERROR_EXIT_CODE)
20
- end
21
-
22
13
  def runner_context
23
14
  return @runner_context if @runner_context
24
15
 
@@ -7,18 +7,19 @@ module EacCli
7
7
  module Help
8
8
  class Builder
9
9
  class Alternative
10
- PROGRAM_MACRO = '__PROGRAM__'
10
+ enable_method_class
11
+
11
12
  SUBCOMMANDS_MACRO = '__SUBCOMMANDS__'
12
13
 
13
- common_constructor :alternative
14
+ common_constructor :builder, :alternative
14
15
 
15
- def to_s
16
+ def result
16
17
  (
17
- [PROGRAM_MACRO] +
18
+ program_name +
18
19
  alternative.options_argument?.if_present([]) { |_v| ['[options]'] } +
19
20
  options +
20
21
  positionals
21
- ).join(::EacCli::RunnerWith::Help::Builder::SEP)
22
+ ).join(builder.word_separator)
22
23
  end
23
24
 
24
25
  def options
@@ -49,6 +50,12 @@ module EacCli
49
50
  r
50
51
  end
51
52
  end
53
+
54
+ def program_name
55
+ r = builder.runner.program_name
56
+ r = [r] unless r.is_a?(::Enumerable)
57
+ r
58
+ end
52
59
  end
53
60
  end
54
61
  end
@@ -6,8 +6,8 @@ module EacCli
6
6
  module RunnerWith
7
7
  module Help
8
8
  class Builder
9
- require_sub __FILE__
10
- common_constructor :definition
9
+ require_sub __FILE__, require_dependency: true
10
+ common_constructor :runner
11
11
 
12
12
  SEP = ' '
13
13
  IDENT = SEP * 2
@@ -28,11 +28,21 @@ module EacCli
28
28
 
29
29
  def option_usage_full(option)
30
30
  if option.long.present?
31
- [option.short, option_long(option)].reject(&:blank?).join(SEP)
31
+ [option.short, option_long(option)].reject(&:blank?).join(word_separator)
32
32
  else
33
33
  option_short(option)
34
34
  end
35
35
  end
36
+
37
+ def word_separator
38
+ SEP
39
+ end
40
+ end
41
+
42
+ delegate :word_separator, to: :class
43
+
44
+ def definition
45
+ runner.class.runner_definition
36
46
  end
37
47
 
38
48
  def option_definition(option)
@@ -45,8 +55,7 @@ module EacCli
45
55
  b = include_header ? "#{header.humanize}:\n" : ''
46
56
  b += send("self_#{header}") + "\n"
47
57
  definition.alternatives.each do |alternative|
48
- b += IDENT + ::EacCli::RunnerWith::Help::Builder::Alternative.new(alternative).to_s +
49
- "\n"
58
+ b += IDENT + self.alternative(alternative) + "\n"
50
59
  end
51
60
  b
52
61
  end
@@ -60,7 +69,7 @@ module EacCli
60
69
  def usage_section
61
70
  "Usage:\n" +
62
71
  definition.alternatives.map do |alternative|
63
- IDENT + ::EacCli::RunnerWith::Help::Builder::Alternative.new(alternative).to_s + "\n"
72
+ IDENT + self.alternative(alternative) + "\n"
64
73
  end.join
65
74
  end
66
75
 
@@ -6,7 +6,7 @@ require 'eac_ruby_utils/core_ext'
6
6
  module EacCli
7
7
  module RunnerWith
8
8
  module Help
9
- require_sub __FILE__
9
+ require_sub __FILE__, require_dependency: true
10
10
  common_concern do
11
11
  include ::EacCli::Runner
12
12
 
@@ -28,7 +28,7 @@ module EacCli
28
28
  end
29
29
 
30
30
  def help_text
31
- r = ::EacCli::RunnerWith::Help::Builder.new(self.class.runner_definition).to_s
31
+ r = ::EacCli::RunnerWith::Help::Builder.new(self).to_s
32
32
  r += help_extra_text if respond_to?(:help_extra_text)
33
33
  r
34
34
  end
@@ -104,7 +104,7 @@ module EacCli
104
104
  end
105
105
 
106
106
  def subcommand_program
107
- subcommand_name
107
+ [program_name, subcommand_name]
108
108
  end
109
109
 
110
110
  def subcommand_runner
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacCli
4
- VERSION = '0.27.3'
4
+ VERSION = '0.27.5'
5
5
  end
@@ -20,23 +20,32 @@ RSpec.describe ::EacCli::RunnerWith::Help do
20
20
  end
21
21
  end
22
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
23
+ [
24
+ ['--help'],
25
+ ['trash-pos-arg-before', '--help', 'trash-pos-arg-after']
26
+ ].each do |runner_argv|
27
+ context "when runner ARGV is #{runner_argv}" do
28
+ let(:instance) { runner.create(argv: runner_argv) }
29
+ let(:expected_output_source) do
30
+ <<~OUTPUT
31
+ A stub runner.
32
+
33
+ Usage:
34
+ __PROGRAM__ [options] <a_argument>
35
+ __PROGRAM__ --help
36
+
37
+ Options:
38
+ -h --help Show help.
39
+
40
+ OUTPUT
41
+ end
42
+ let(:expected_output) do
43
+ expected_output_source.gsub('__PROGRAM__', instance.program_name)
44
+ end
38
45
 
39
- it 'show help text' do
40
- expect { instance.run_run }.to output(expected_output).to_stdout_from_any_process
46
+ it 'show help text' do
47
+ expect { instance.run_run }.to output(expected_output).to_stdout_from_any_process
48
+ end
49
+ end
41
50
  end
42
51
  end
@@ -57,7 +57,7 @@ RSpec.describe ::EacCli::RunnerWith::Subcommands do
57
57
 
58
58
  context 'with help' do
59
59
  let(:instance) { parent_runner.create(%w[--help]) }
60
- let(:expected_output) do
60
+ let(:expected_output_source) do
61
61
  <<~OUTPUT
62
62
  A stub root runner.
63
63
 
@@ -73,6 +73,9 @@ RSpec.describe ::EacCli::RunnerWith::Subcommands do
73
73
  child-cmd
74
74
  OUTPUT
75
75
  end
76
+ let(:expected_output) do
77
+ expected_output_source.gsub('__PROGRAM__', instance.program_name)
78
+ end
76
79
 
77
80
  before do
78
81
  parent_runner.include(::EacCli::RunnerWith::Help)
@@ -12,10 +12,10 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = Dir['{lib}/**/*']
14
14
 
15
- s.add_dependency 'eac_cli', '~> 0.26'
15
+ s.add_dependency 'eac_cli', '~> 0.27', '>= 0.27.5'
16
16
  s.add_dependency 'eac_fs', '~> 0.10'
17
17
  s.add_dependency 'eac_ruby_gems_utils', '~> 0.9', '~> 0.9.6'
18
- s.add_dependency 'eac_ruby_utils', '~> 0.70'
18
+ s.add_dependency 'eac_ruby_utils', '~> 0.95', '>= 0.95.1'
19
19
 
20
20
  s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5.1'
21
21
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyBase0
4
- VERSION = '0.16.2'
4
+ VERSION = '0.16.4'
5
5
  end
@@ -68,12 +68,12 @@ module EacRubyUtils
68
68
 
69
69
  def setup_class_attr_readers(klass)
70
70
  klass.send(:attr_reader, *args)
71
- klass.send(:public, *args)
71
+ klass.send(:public, *args) if args.any?
72
72
  end
73
73
 
74
74
  def setup_class_attr_writers(klass)
75
75
  klass.send(:attr_writer, *args)
76
- klass.send(:private, *args.map { |a| "#{a}=" })
76
+ klass.send(:private, *args.map { |a| "#{a}=" }) if args.any?
77
77
  end
78
78
 
79
79
  def setup_class_initialize(klass)
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/locales/from_all_gems'
3
4
  require 'eac_ruby_utils/patches'
4
5
  require 'active_support/dependencies/autoload'
5
6
  require 'active_support/core_ext'
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/locales/from_gem'
4
+ ::EacRubyUtils::Locales::FromGem.include_all
@@ -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,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+
5
+ module EacRubyUtils
6
+ module Locales
7
+ ::EacRubyUtils.require_sub __FILE__
8
+ end
9
+ 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 'active_support/core_ext/string/inflections'
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
- on_i18n_locale(values.delete(TRANSLATE_LOCALE_KEY)) do
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
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/method_class'
4
+
5
+ class Module
6
+ def enable_method_class
7
+ ::EacRubyUtils.patch(self, ::EacRubyUtils::MethodClass)
8
+ end
9
+ end