avm-tools 0.94.0 → 0.96.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/app_src.rb +60 -0
- data/lib/avm/core_ext.rb +4 -0
- data/lib/avm/eac_webapp_base0/instance.rb +5 -2
- data/lib/avm/eac_webapp_base0/instance/subcommand_parent.rb +24 -0
- data/lib/avm/eac_webapp_base0/runner/data.rb +1 -0
- data/lib/avm/eac_webapp_base0/runner/data/dump.rb +1 -1
- data/lib/avm/eac_webapp_base0/runner/data/load.rb +1 -1
- data/lib/avm/git/file_auto_fixup.rb +12 -2
- data/lib/avm/instances/base.rb +6 -12
- data/lib/avm/instances/base/entry_keys.rb +17 -0
- data/lib/{eac_launcher → avm/launcher}/instances/error.rb +0 -0
- data/lib/avm/launcher/instances/runner_helper.rb +42 -0
- data/lib/avm/patches/class.rb +4 -0
- data/lib/avm/patches/eac_ruby_gems_utils.rb +4 -0
- data/lib/avm/patches/object.rb +4 -0
- data/lib/avm/patches/object/fs_cache.rb +16 -0
- data/lib/avm/ruby/bundler.rb +11 -0
- data/lib/avm/ruby/bundler/incompatible_parser.rb +25 -0
- data/lib/avm/ruby/bundler/incompatible_parser/depends_on.rb +25 -0
- data/lib/avm/ruby/bundler/incompatible_parser/gem_conflict.rb +39 -0
- data/lib/avm/ruby/bundler/incompatible_parser/in_gemfile.rb +19 -0
- data/lib/avm/ruby/bundler/incompatible_parser/line_buffer.rb +73 -0
- data/lib/avm/ruby/bundler/incompatible_parser/line_factory.rb +31 -0
- data/lib/avm/ruby/bundler/incompatible_parser/line_parser_base.rb +19 -0
- data/lib/avm/ruby/bundler/incompatible_parser/version_requirement.rb +26 -0
- data/lib/avm/ruby/gems/generator.rb +1 -5
- data/lib/avm/tools/runner/{local_project.rb → app_src.rb} +3 -3
- data/lib/avm/tools/runner/{local_project → app_src}/eac_asciidoctor_base0.rb +1 -1
- data/lib/avm/tools/runner/{local_project → app_src}/eac_asciidoctor_base0/build.rb +2 -3
- data/lib/avm/tools/runner/{local_project → app_src}/eac_writings_base0.rb +1 -1
- data/lib/avm/tools/runner/{local_project → app_src}/eac_writings_base0/build_chapters.rb +1 -1
- data/lib/avm/tools/runner/{local_project → app_src}/eac_writings_base0/build_single.rb +1 -1
- data/lib/avm/tools/runner/{local_project → app_src}/eac_writings_base0/info.rb +1 -1
- data/lib/avm/tools/runner/{local_project → app_src}/info.rb +1 -1
- data/lib/avm/tools/runner/{local_project → app_src}/ruby.rb +3 -7
- data/lib/avm/tools/runner/{local_project → app_src}/ruby/bundler.rb +4 -8
- data/lib/avm/tools/runner/{local_project → app_src}/ruby/bundler/gemfile_lock.rb +11 -14
- data/lib/avm/tools/runner/app_src/ruby/bundler/incompatible.rb +84 -0
- data/lib/avm/tools/runner/{local_project → app_src}/test.rb +1 -1
- data/lib/avm/tools/runner/{local_project → app_src}/update.rb +1 -1
- data/lib/avm/tools/runner/{local_project → app_src}/version_bump.rb +1 -1
- data/lib/avm/tools/runner/git/subrepo/fix.rb +1 -1
- data/lib/avm/tools/runner/launcher.rb +3 -6
- data/lib/avm/tools/runner/launcher/instances.rb +10 -21
- data/lib/avm/tools/runner/launcher/projects.rb +10 -18
- data/lib/avm/tools/runner/launcher/publish.rb +18 -26
- data/lib/avm/tools/runner/ruby/rubocop.rb +9 -25
- data/lib/avm/tools/runner/self.rb +7 -15
- data/lib/avm/tools/runner/self/docker.rb +1 -1
- data/lib/avm/tools/version.rb +1 -1
- data/lib/eac_launcher/instances.rb +1 -1
- data/template/avm/ruby/gems/generator/static/spec/rubocop_spec.rb +1 -5
- data/template/avm/ruby/gems/generator/static/spec/spec_helper.rb +2 -0
- data/vendor/avm-apps/avm-apps.gemspec +1 -1
- data/vendor/avm-apps/lib/avm/apps/version.rb +1 -1
- data/vendor/avm-apps/spec/rubocop_spec.rb +1 -5
- data/vendor/avm-apps/spec/spec_helper.rb +3 -0
- data/vendor/eac_cli/eac_cli.gemspec +1 -1
- data/vendor/eac_cli/lib/eac_cli/core_ext.rb +2 -0
- data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +5 -1
- data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +3 -1
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/short_options.rb +4 -2
- data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +2 -1
- data/vendor/eac_cli/lib/eac_cli/runner/context.rb +2 -1
- data/vendor/eac_cli/lib/eac_cli/runner/instance_methods.rb +8 -1
- data/vendor/eac_cli/lib/eac_cli/runner_with_set.rb +50 -0
- data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
- data/vendor/eac_cli/spec/rubocop_spec.rb +1 -5
- data/vendor/eac_cli/spec/spec_helper.rb +3 -0
- data/vendor/eac_docker/eac_docker.gemspec +1 -1
- data/vendor/eac_docker/lib/eac_docker/version.rb +1 -1
- data/vendor/eac_docker/spec/rubocop_spec.rb +1 -5
- data/vendor/eac_docker/spec/spec_helper.rb +3 -0
- data/vendor/eac_git/eac_git.gemspec +2 -1
- data/vendor/eac_git/lib/eac_git/local.rb +4 -0
- data/vendor/eac_git/lib/eac_git/local/commit.rb +53 -0
- data/vendor/eac_git/lib/eac_git/local/commit/changed_file.rb +46 -0
- data/vendor/eac_git/lib/eac_git/local/commit/diff_tree_line.rb +32 -0
- data/vendor/eac_git/lib/eac_git/local/dirty_files.rb +2 -3
- data/vendor/eac_git/lib/eac_git/rspec.rb +6 -1
- data/{lib/avm/git/spec_helper.rb → vendor/eac_git/lib/eac_git/rspec/stubbed_git_local_repo.rb} +16 -13
- data/vendor/eac_git/lib/eac_git/version.rb +1 -1
- data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec.rb +13 -0
- data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/add.source.out +1 -0
- data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/add.target.yaml +7 -0
- data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/modify.source.out +1 -0
- data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/modify.target.yaml +7 -0
- data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/remove.source.out +1 -0
- data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/remove.target.yaml +7 -0
- data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/rename.source.out +2 -0
- data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/rename.target.yaml +13 -0
- data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/rename_modify.source.out +2 -0
- data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/rename_modify.target.yaml +13 -0
- data/vendor/eac_git/spec/lib/eac_git/local/commit_spec.rb +58 -0
- data/vendor/eac_git/spec/rubocop_spec.rb +1 -5
- data/vendor/eac_git/spec/spec_helper.rb +3 -0
- data/vendor/eac_ruby_base0/eac_ruby_base0.gemspec +4 -4
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/core_ext.rb +4 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/jobs_runner.rb +31 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/patches.rb +4 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/patches/class.rb +4 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/patches/class/jobs_runner.rb +10 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/patches/object.rb +5 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/patches/object/runner_with.rb +5 -0
- data/{lib/avm/local_projects.rb → vendor/eac_ruby_base0/lib/eac_ruby_base0/runner_with.rb} +2 -2
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner_with/confirmation.rb +36 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner_with/filesystem_traverser.rb +52 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner_with/input.rb +36 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner_with/output.rb +58 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
- data/vendor/eac_ruby_base0/spec/lib/eac_ruby_base0/runner_with/confirmation_spec.rb +42 -0
- data/vendor/eac_ruby_base0/spec/lib/eac_ruby_base0/runner_with/output_spec.rb +81 -0
- data/vendor/eac_ruby_base0/spec/rubocop_spec.rb +1 -5
- data/vendor/eac_ruby_base0/spec/spec_helper.rb +3 -0
- data/vendor/eac_ruby_gems_utils/eac_ruby_gems_utils.gemspec +1 -1
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/base.rb +7 -10
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/multiple.rb +9 -2
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/version.rb +1 -1
- data/vendor/eac_ruby_gems_utils/spec/code/rubocop_check_spec.rb +1 -5
- data/vendor/eac_ruby_gems_utils/spec/spec_helper.rb +3 -0
- data/vendor/eac_ruby_utils/eac_ruby_utils.gemspec +2 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/filesystem_cache.rb +6 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/logs.rb +63 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb +9 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/list.rb +3 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/local_time_zone.rb +8 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/class/settings_provider.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/kernel/nyi.rb +4 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_nil.rb +17 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/regexp/to_parser.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string/inflector.rb +4 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/required_zone.rb +11 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/regexp_parser.rb +34 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/settings_provider.rb +10 -29
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/settings_provider/setting_value.rb +69 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/simple_cache.rb +18 -5
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/settings_provider_spec.rb +8 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/simple_cache_spec.rb +9 -0
- data/vendor/eac_ruby_utils/spec/rubocop_check_spec.rb +1 -5
- data/vendor/eac_ruby_utils/spec/spec_helper.rb +3 -0
- metadata +77 -32
- data/lib/avm/local_projects/instance.rb +0 -62
- data/lib/eac_launcher/instances/runner_helper.rb +0 -42
- data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +0 -30
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb +0 -53
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_base0/runner_with/confirmation'
|
4
|
+
|
5
|
+
::RSpec.describe ::EacRubyBase0::RunnerWith::Confirmation do
|
6
|
+
let(:runner) do
|
7
|
+
the_module = described_class
|
8
|
+
Class.new do
|
9
|
+
include the_module
|
10
|
+
|
11
|
+
runner_definition do
|
12
|
+
desc 'A stub runner.'
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
if confirm?
|
17
|
+
::Kernel.puts 'Accepted'
|
18
|
+
else
|
19
|
+
::Kernel.puts 'Denied'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:instance) { runner.create(argv: runner_argv) }
|
26
|
+
|
27
|
+
context 'without --no option' do
|
28
|
+
let(:runner_argv) { %w[--no] }
|
29
|
+
|
30
|
+
it do
|
31
|
+
expect { instance.run }.to output("Denied\n").to_stdout_from_any_process
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'without --yes option' do
|
36
|
+
let(:runner_argv) { %w[--yes] }
|
37
|
+
|
38
|
+
it do
|
39
|
+
expect { instance.run }.to output("Accepted\n").to_stdout_from_any_process
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -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,7 +1,3 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
RSpec.describe ::RuboCop, slow: true do
|
6
|
-
include_examples 'rubocop_check', ::File.expand_path('..', __dir__)
|
7
|
-
end
|
3
|
+
::EacRubyGemSupport::Rspec.default.describe_rubocop
|
@@ -97,4 +97,7 @@ RSpec.configure do |config|
|
|
97
97
|
# # test failures related to randomization by passing the same `--seed` value
|
98
98
|
# # as the one that triggered the failure.
|
99
99
|
# Kernel.srand config.seed
|
100
|
+
|
101
|
+
require 'eac_ruby_gem_support/rspec'
|
102
|
+
::EacRubyGemSupport::Rspec.setup(::File.expand_path('..', __dir__), config)
|
100
103
|
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
|
-
|
57
|
-
|
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
|
-
|
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
|
@@ -97,4 +97,7 @@ RSpec.configure do |config|
|
|
97
97
|
# # test failures related to randomization by passing the same `--seed` value
|
98
98
|
# # as the one that triggered the failure.
|
99
99
|
# Kernel.srand config.seed
|
100
|
+
|
101
|
+
require 'eac_ruby_gem_support/rspec'
|
102
|
+
::EacRubyGemSupport::Rspec.setup(::File.expand_path('..', __dir__), config)
|
100
103
|
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
|
-
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.
|
24
|
+
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.2'
|
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
|
-
|
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
|
-
|
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.
|
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]
|
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
|
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
module Kernel
|
4
4
|
# Raise exception with text "Not yet implemented".
|
5
|
-
def nyi
|
6
|
-
|
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
|