avm-tools 0.92.0 → 0.94.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/eac_asciidoctor_base0/apache_path.rb +10 -0
  3. data/lib/avm/eac_rails_base0/apache_path.rb +6 -38
  4. data/lib/avm/eac_webapp_base0/apache_host.rb +7 -31
  5. data/lib/avm/eac_webapp_base0/apache_path.rb +51 -0
  6. data/lib/avm/eac_webapp_base0/deploy.rb +12 -30
  7. data/lib/avm/eac_webapp_base0/instance.rb +5 -2
  8. data/lib/avm/eac_webapp_base0/instance/subcommand_parent.rb +24 -0
  9. data/lib/avm/eac_webapp_base0/runner/apache_host.rb +7 -10
  10. data/lib/avm/eac_webapp_base0/runner/apache_path.rb +40 -0
  11. data/lib/avm/eac_webapp_base0/runner/data.rb +7 -15
  12. data/lib/avm/eac_webapp_base0/runner/data/dump.rb +18 -24
  13. data/lib/avm/eac_webapp_base0/runner/data/load.rb +12 -23
  14. data/lib/avm/git/auto_commit/commit_info.rb +2 -1
  15. data/lib/avm/git/auto_commit/rules.rb +4 -4
  16. data/lib/avm/git/auto_commit/rules/new.rb +24 -0
  17. data/lib/avm/git/auto_commit/rules/nth.rb +8 -0
  18. data/lib/avm/git/auto_commit_path.rb +0 -21
  19. data/lib/avm/git/file_auto_fixup.rb +19 -3
  20. data/lib/avm/tools/runner/eac_redmine_base0/core_update.rb +7 -11
  21. data/lib/avm/tools/runner/git/auto_commit.rb +28 -28
  22. data/lib/avm/tools/runner/git/subrepo/fix.rb +1 -1
  23. data/lib/avm/tools/runner/local_project/ruby.rb +3 -7
  24. data/lib/avm/tools/runner/local_project/ruby/bundler.rb +4 -8
  25. data/lib/avm/tools/runner/local_project/ruby/bundler/gemfile_lock.rb +11 -14
  26. data/lib/avm/tools/runner/ruby.rb +6 -14
  27. data/lib/avm/tools/runner/ruby/gems.rb +4 -7
  28. data/lib/avm/tools/runner/ruby/gems/generate.rb +12 -23
  29. data/lib/avm/tools/runner/ruby/rubocop.rb +1 -1
  30. data/lib/avm/tools/version.rb +1 -1
  31. data/template/avm/eac_rails_base0/apache_path/extra_content.conf +5 -0
  32. data/template/avm/eac_webapp_base0/apache_path/default.conf +9 -0
  33. data/vendor/avm-apps/Gemfile +5 -0
  34. data/vendor/avm-apps/avm-apps.gemspec +18 -0
  35. data/vendor/avm-apps/lib/avm/apps.rb +9 -0
  36. data/vendor/avm-apps/lib/avm/apps/jobs.rb +11 -0
  37. data/vendor/avm-apps/lib/avm/apps/jobs/base.rb +64 -0
  38. data/vendor/avm-apps/lib/avm/apps/jobs/variables_source.rb +24 -0
  39. data/vendor/avm-apps/lib/avm/apps/version.rb +7 -0
  40. data/vendor/avm-apps/spec/rubocop_spec.rb +7 -0
  41. data/vendor/avm-apps/spec/spec_helper.rb +100 -0
  42. data/vendor/eac_cli/lib/eac_cli/core_ext.rb +2 -0
  43. data/vendor/eac_cli/lib/eac_cli/definition/alternative.rb +4 -7
  44. data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +20 -9
  45. data/vendor/eac_cli/lib/eac_cli/definition/base_option/initialize_args_parser.rb +47 -0
  46. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +15 -1
  47. data/vendor/eac_cli/lib/eac_cli/parser/alternative/short_options.rb +4 -2
  48. data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +2 -1
  49. data/vendor/eac_cli/lib/eac_cli/runner/context.rb +2 -1
  50. data/vendor/eac_cli/lib/eac_cli/runner/instance_methods.rb +8 -1
  51. data/vendor/eac_cli/lib/eac_cli/runner_with_set.rb +50 -0
  52. data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
  53. data/vendor/eac_cli/spec/lib/eac_cli/definition/alternative_spec.rb +4 -0
  54. data/vendor/eac_git/eac_git.gemspec +1 -0
  55. data/vendor/eac_git/lib/eac_git/local.rb +4 -0
  56. data/vendor/eac_git/lib/eac_git/local/commit.rb +53 -0
  57. data/vendor/eac_git/lib/eac_git/local/commit/changed_file.rb +46 -0
  58. data/vendor/eac_git/lib/eac_git/local/commit/diff_tree_line.rb +32 -0
  59. data/vendor/eac_git/lib/eac_git/local/dirty_files.rb +2 -3
  60. data/vendor/eac_git/lib/eac_git/rspec.rb +6 -1
  61. data/{lib/avm/git/spec_helper.rb → vendor/eac_git/lib/eac_git/rspec/stubbed_git_local_repo.rb} +16 -13
  62. data/vendor/eac_git/lib/eac_git/version.rb +1 -1
  63. data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec.rb +13 -0
  64. data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/add.source.out +1 -0
  65. data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/add.target.yaml +7 -0
  66. data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/modify.source.out +1 -0
  67. data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/modify.target.yaml +7 -0
  68. data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/remove.source.out +1 -0
  69. data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/remove.target.yaml +7 -0
  70. data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/rename.source.out +2 -0
  71. data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/rename.target.yaml +13 -0
  72. data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/rename_modify.source.out +2 -0
  73. data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/rename_modify.target.yaml +13 -0
  74. data/vendor/eac_git/spec/lib/eac_git/local/commit_spec.rb +58 -0
  75. data/vendor/eac_git/spec/spec_helper.rb +1 -0
  76. data/vendor/eac_ruby_base0/eac_ruby_base0.gemspec +3 -3
  77. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/core_ext.rb +4 -0
  78. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/jobs_runner.rb +31 -0
  79. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/patches.rb +4 -0
  80. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/patches/class.rb +4 -0
  81. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/patches/class/jobs_runner.rb +10 -0
  82. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/patches/object.rb +5 -0
  83. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/patches/object/runner_with.rb +5 -0
  84. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner_with.rb +9 -0
  85. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner_with/confirmation.rb +36 -0
  86. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner_with/filesystem_traverser.rb +52 -0
  87. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner_with/output.rb +58 -0
  88. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
  89. data/vendor/eac_ruby_base0/spec/lib/eac_ruby_base0/runner_with/confirmation_spec.rb +42 -0
  90. data/vendor/eac_ruby_base0/spec/lib/eac_ruby_base0/runner_with/output_spec.rb +81 -0
  91. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/base.rb +7 -10
  92. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/multiple.rb +9 -2
  93. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/version.rb +1 -1
  94. data/vendor/eac_ruby_utils/eac_ruby_utils.gemspec +1 -0
  95. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/logs.rb +63 -0
  96. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb +9 -1
  97. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/list.rb +3 -2
  98. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/local_time_zone.rb +8 -2
  99. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/class/settings_provider.rb +10 -0
  100. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/kernel/nyi.rb +4 -2
  101. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_nil.rb +17 -0
  102. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string/inflector.rb +4 -2
  103. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/required_zone.rb +11 -0
  104. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/settings_provider.rb +10 -29
  105. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/settings_provider/setting_value.rb +69 -0
  106. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  107. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/settings_provider_spec.rb +8 -0
  108. metadata +55 -9
  109. data/lib/avm/tools/runner/eac_rails_base0/apache_path.rb +0 -38
  110. data/lib/avm/tools/runner/git/auto_fixup.rb +0 -53
  111. data/template/avm/eac_rails_base0/apache_path/default.conf +0 -13
  112. data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +0 -30
  113. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb +0 -53
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_base0/runner_with/output'
4
+ require 'eac_ruby_utils/fs/temp'
5
+
6
+ RSpec.describe ::EacRubyBase0::RunnerWith::Output do
7
+ let(:runner) do
8
+ the_module = described_class
9
+ Class.new do
10
+ include the_module
11
+
12
+ attr_accessor :temp_dir
13
+
14
+ runner_definition do
15
+ desc 'A stub root runner.'
16
+ pos_arg :input_text
17
+ end
18
+
19
+ def run
20
+ run_output
21
+ end
22
+
23
+ def output_content
24
+ parsed.input_text
25
+ end
26
+
27
+ def default_file_to_output
28
+ temp_dir.join('default_file')
29
+ end
30
+ end
31
+ end
32
+
33
+ let(:stub_text) { 'STUB_TEXT' }
34
+ let(:instance) do
35
+ r = runner.create(argv: runner_argv)
36
+ r.temp_dir = temp_dir
37
+ r
38
+ end
39
+ let(:temp_dir) { ::EacRubyUtils::Fs::Temp.directory }
40
+
41
+ after { temp_dir.remove }
42
+
43
+ context 'without --output option' do
44
+ let(:runner_argv) { [stub_text] }
45
+
46
+ it do
47
+ expect { instance.run }.to output(stub_text).to_stdout_from_any_process
48
+ end
49
+ end
50
+
51
+ context 'without --output option as to stdout' do
52
+ let(:runner_argv) { ['--output', ::EacRubyBase0::RunnerWith::Output::STDOUT_OPTION, stub_text] }
53
+
54
+ it do
55
+ expect { instance.run }.to output(stub_text).to_stdout_from_any_process
56
+ end
57
+ end
58
+
59
+ context 'without --output option as to default file' do
60
+ let(:output_file) { temp_dir.join('default_file') }
61
+ let(:runner_argv) do
62
+ ['--output', ::EacRubyBase0::RunnerWith::Output::DEFAULT_FILE_OPTION,
63
+ stub_text]
64
+ end
65
+
66
+ before { instance.run }
67
+
68
+ it { expect(output_file).to exist }
69
+ it { expect(output_file.read).to eq(stub_text) }
70
+ end
71
+
72
+ context 'with --output option' do
73
+ let(:output_file) { temp_dir.join('a output file') }
74
+ let(:runner_argv) { ['--output', output_file.to_path, stub_text] }
75
+
76
+ before { instance.run }
77
+
78
+ it { expect(output_file).to exist }
79
+ it { expect(output_file.read).to eq(stub_text) }
80
+ end
81
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/fs/logs'
4
5
  require 'eac_ruby_utils/fs_cache'
5
6
  require 'eac_ruby_utils/listable'
6
7
  require 'eac_ruby_utils/on_clean_ruby_environment'
@@ -27,20 +28,16 @@ module EacRubyGemsUtils
27
28
  self.class.name.demodulize.gsub(/Test\z/, '')
28
29
  end
29
30
 
30
- def stdout_cache
31
- root_cache.child('stdout')
32
- end
33
-
34
- def stderr_cache
35
- root_cache.child('stderr')
36
- end
37
-
38
31
  def to_s
39
32
  "#{gem}[#{name}]"
40
33
  end
41
34
 
42
35
  private
43
36
 
37
+ def logs_uncached
38
+ ::EacRubyUtils::Fs::Logs.new.add(:stdout).add(:stderr)
39
+ end
40
+
44
41
  def result_uncached
45
42
  return RESULT_NONEXISTENT unless elegible?
46
43
 
@@ -53,8 +50,8 @@ module EacRubyGemsUtils
53
50
 
54
51
  def exec_run_with_log
55
52
  r = exec_run
56
- stdout_cache.write(r[:stdout])
57
- stderr_cache.write(r[:stderr])
53
+ logs[:stdout].write(r[:stdout])
54
+ logs[:stderr].write(r[:stderr])
58
55
  r[:exit_code].zero?
59
56
  end
60
57
 
@@ -27,6 +27,12 @@ module EacRubyGemsUtils
27
27
  decorated_gems.flat_map(&:tests)
28
28
  end
29
29
 
30
+ def clear_logs
31
+ all_tests.each do |test|
32
+ test.logs.remove_all
33
+ end
34
+ end
35
+
30
36
  def prepare_all_gems
31
37
  infom 'Preparing all gems...'
32
38
  decorated_gems.each(&:prepare)
@@ -47,8 +53,7 @@ module EacRubyGemsUtils
47
53
  warn 'Some test did not pass:'
48
54
  failed_tests.each do |test|
49
55
  infov ' * Test', test
50
- infov ' * STDOUT', test.stdout_cache.content_path
51
- infov ' * STDERR', test.stderr_cache.content_path
56
+ info test.logs.truncate_all
52
57
  end
53
58
  else
54
59
  success 'All tests passed'
@@ -60,6 +65,8 @@ module EacRubyGemsUtils
60
65
  prepare_all_gems
61
66
  test_all_gems
62
67
  final_results_banner
68
+ ensure
69
+ clear_logs
63
70
  end
64
71
 
65
72
  def start_banner
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyGemsUtils
4
- VERSION = '0.8.0'
4
+ VERSION = '0.9.0'
5
5
  end
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.add_dependency 'addressable', '~> 2.6'
20
20
  s.add_dependency 'colorize', '~> 0.8.1'
21
21
  s.add_dependency 'docopt', '~> 0.6.1'
22
+ s.add_dependency 'filesize'
22
23
  s.add_dependency 'net-ssh', '~> 4.2'
23
24
  s.add_development_dependency 'eac_ruby_gem_support', '~> 0.1', '>= 0.1.1'
24
25
  end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/string/filters'
4
+ require 'eac_ruby_utils/fs/temp'
5
+ require 'filesize'
6
+
7
+ module EacRubyUtils
8
+ module Fs
9
+ class Logs
10
+ TRUNCATE_DEFAULT_LENGTH = 1000
11
+ TRUNCATE_APPEND_TEXT = '(...) '
12
+
13
+ def [](label)
14
+ log_set.fetch(sanitize_label(label))
15
+ end
16
+
17
+ def add(label)
18
+ log_set[sanitize_label(label)] = ::EacRubyUtils::Fs::Temp.file
19
+
20
+ self
21
+ end
22
+
23
+ def remove_all
24
+ log_set.each_key { |label| remove(label) }
25
+
26
+ self
27
+ end
28
+
29
+ def remove(label)
30
+ log_set.fetch(sanitize_label(label)).remove
31
+ log_set.delete(sanitize_label(label))
32
+ end
33
+
34
+ def truncate(label, length = TRUNCATE_DEFAULT_LENGTH)
35
+ content = self[label].read.strip
36
+ return content if content.length <= TRUNCATE_DEFAULT_LENGTH
37
+
38
+ TRUNCATE_APPEND_TEXT + content[content.length - length + TRUNCATE_APPEND_TEXT.length,
39
+ length - TRUNCATE_APPEND_TEXT.length]
40
+ end
41
+
42
+ def truncate_all(length = TRUNCATE_DEFAULT_LENGTH)
43
+ s = "Files: #{log_set.length}\n"
44
+ log_set.each do |label, path|
45
+ x = truncate(label, length)
46
+ y = [label, path, ::Filesize.from("#{path.size} B").pretty].join(' / ')
47
+ s += x.blank? ? ">>> #{y} (Blank) <<<" : ">>> #{y}\n#{x}\n<<< #{y}\n"
48
+ end
49
+ s
50
+ end
51
+
52
+ private
53
+
54
+ def sanitize_label(label)
55
+ label.to_sym
56
+ end
57
+
58
+ def log_set
59
+ @log_set ||= {}
60
+ end
61
+ end
62
+ end
63
+ end
@@ -7,11 +7,19 @@ module EacRubyUtils
7
7
  class << self
8
8
  VARIABLE_NAME_PATTERN = /[_a-z][_a-z0-9]*/i.freeze
9
9
 
10
- def variableize(string)
10
+ # Convert a string to a variable format: first character as a lowercase letter or underscore
11
+ # and other as a lowercase letter, underscore or numbers.
12
+ # @param string [String] The source string.
13
+ # @param validate [Boolean] Affect the outcome when the result builded is not in a valid
14
+ # variable format. If `true`, it raises a {ArgumentError}. If `false`, return `nil`.
15
+ # @return [String, nil]
16
+ # @raise [ArgumentError]
17
+ def variableize(string, validate = true)
11
18
  r = ::ActiveSupport::Inflector.transliterate(string).gsub(/[^_a-z0-9]/i, '_')
12
19
  .gsub(/_+/, '_').gsub(/_\z/, '').gsub(/\A_/, '').downcase
13
20
  m = VARIABLE_NAME_PATTERN.match(r)
14
21
  return r if m
22
+ return nil unless validate
15
23
 
16
24
  raise ::ArgumentError, "Invalid variable name \"#{r}\" was generated " \
17
25
  "from string \"#{string}\""
@@ -54,8 +54,9 @@ module EacRubyUtils
54
54
  end
55
55
 
56
56
  def value_validate!(value, error_class = ::StandardError)
57
- value_valid?(value) ||
58
- raise(error_class, "Invalid value: \"#{value}\" (Valid: #{values_to_s})")
57
+ return value if value_valid?(value)
58
+
59
+ raise(error_class, "Invalid value: \"#{value}\" (Valid: #{values_to_s})")
59
60
  end
60
61
 
61
62
  def values_to_s
@@ -10,6 +10,7 @@ module EacRubyUtils
10
10
  class << self
11
11
  TIMEDATECTL_TIMEZONE_LINE_PATTERN = %r{\s*Time zone:\s*(\S+/\S+)\s}.freeze
12
12
 
13
+ # @return [ActiveSupport::TimeZone]
13
14
  def auto
14
15
  %w[tz_env debian_config offset].lazy.map { |s| send("by_#{s}") }.find(&:present?)
15
16
  end
@@ -18,22 +19,27 @@ module EacRubyUtils
18
19
  ::Time.zone = auto
19
20
  end
20
21
 
22
+ # @return [ActiveSupport::TimeZone]
21
23
  def by_debian_config
22
24
  path = ::Pathname.new(DEBIAN_CONFIG_PATH)
23
- path.exist? ? path.read.strip.presence : nil
25
+ path.exist? ? path.read.strip.if_present { |v| ::ActiveSupport::TimeZone[v] } : nil
24
26
  end
25
27
 
28
+ # @return [ActiveSupport::TimeZone]
26
29
  def by_offset
27
- ::ActiveSupport::TimeZone[::Time.now.getlocal.gmt_offset].name
30
+ ::ActiveSupport::TimeZone[::Time.now.getlocal.gmt_offset]
28
31
  end
29
32
 
33
+ # @return [ActiveSupport::TimeZone]
30
34
  def by_timedatectl
31
35
  executable = ::EacRubyUtils::Envs.local.executable('timedatectl', '--version')
32
36
  return nil unless executable.exist?
33
37
 
34
38
  TIMEDATECTL_TIMEZONE_LINE_PATTERN.if_match(executable.command.execute!) { |m| m[1] }
39
+ .if_present { |v| ::ActiveSupport::TimeZone[v] }
35
40
  end
36
41
 
42
+ # @return [ActiveSupport::TimeZone]
37
43
  def by_tz_env
38
44
  ENV['TZ'].presence
39
45
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patch'
4
+ require 'eac_ruby_utils/settings_provider'
5
+
6
+ class Class
7
+ def enable_settings_provider
8
+ ::EacRubyUtils.patch(self, ::EacRubyUtils::SettingsProvider)
9
+ end
10
+ end
@@ -2,7 +2,9 @@
2
2
 
3
3
  module Kernel
4
4
  # Raise exception with text "Not yet implemented".
5
- def nyi
6
- raise "Not yet implemented (Called in #{caller.first})"
5
+ def nyi(message = nil)
6
+ s = "Not yet implemented (Called in #{caller.first})"
7
+ s += ": #{message}" if message
8
+ raise s
7
9
  end
8
10
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Object
4
+ # @return +block.call(self)+ if +self+ is not nil, +default_value+ otherwise.
5
+ def if_not_nil(default_value = nil)
6
+ return default_value if nil?
7
+
8
+ block_given? ? yield(self) : self
9
+ end
10
+
11
+ # @return +yield+ if +self+ is nil, +self+ otherwise.
12
+ def if_nil
13
+ return yield if nil? && block_given?
14
+
15
+ self
16
+ end
17
+ end
@@ -3,7 +3,9 @@
3
3
  require 'eac_ruby_utils/inflector'
4
4
 
5
5
  class String
6
- def variableize
7
- ::EacRubyUtils::Inflector.variableize(self)
6
+ # Shortcut to `EacRubyUtils::Inflector.variableize(self, ...)`.
7
+ # @see EacRubyUtils::Inflector.variableize
8
+ def variableize(validate = true)
9
+ ::EacRubyUtils::Inflector.variableize(self, validate)
8
10
  end
9
11
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/local_time_zone'
4
+
5
+ class Time
6
+ class << self
7
+ def required_zone
8
+ zone || ::EacRubyUtils::LocalTimeZone.auto || raise('No zone set or discovered')
9
+ end
10
+ end
11
+ end
@@ -1,15 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/core_ext/string/inflections'
4
- require 'eac_ruby_utils/options_consumer'
3
+ require 'eac_ruby_utils/require_sub'
5
4
 
6
5
  module EacRubyUtils
7
6
  # Provide a option by constant, method or options object.
8
7
  module SettingsProvider
8
+ ::EacRubyUtils.require_sub __FILE__, base: self
9
+
9
10
  def setting_constant_name(key, fullname = false)
10
- name = key.to_s.underscore.upcase
11
- name = "#{self.class.name}::#{name}" if fullname
12
- name
11
+ setting_value_instance(key).constant_name(fullname)
13
12
  end
14
13
 
15
14
  def setting_search_order
@@ -25,41 +24,23 @@ module EacRubyUtils
25
24
  end
26
25
 
27
26
  def setting_value(key, options = {})
28
- options = parse_setting_value_options(options)
29
- options.order.each do |method|
30
- value = send("setting_value_by_#{method}", key)
31
- return value if value
32
- end
33
- return nil unless options.required
34
-
35
- raise "Setting \"#{key}\" not found. Supply in #{settings_object_name}, implement a " \
36
- "\"#{key}\" method or declare a #{setting_constant_name(key, true)} constant."
27
+ setting_value_instance(key, options).value
37
28
  end
38
29
 
39
30
  def setting_value_by_constant(key)
40
- constant_name = setting_constant_name(key)
41
- begin
42
- self.class.const_get(constant_name)
43
- rescue NameError
44
- nil
45
- end
31
+ setting_value_instance(key).value_by_constant
46
32
  end
47
33
 
48
34
  def setting_value_by_method(key)
49
- respond_to?(key) ? send(key) : nil
35
+ setting_value_instance(key).value_by_method
50
36
  end
51
37
 
52
38
  def setting_value_by_settings_object(key)
53
- settings_object[key.to_s] || settings_object[key.to_sym]
39
+ setting_value_instance(key).value_by_settings_object
54
40
  end
55
41
 
56
- private
57
-
58
- def parse_setting_value_options(options)
59
- r = ::EacRubyUtils::OptionsConsumer.new(options).consume_all(:required, :order, ostruct: true)
60
- r.required = true if r.required.nil?
61
- r.order = setting_search_order if r.order.nil?
62
- r
42
+ def setting_value_instance(key, options = {})
43
+ ::EacRubyUtils::SettingsProvider::SettingValue.new(self, key, options)
63
44
  end
64
45
  end
65
46
  end