avm-tools 0.93.0 → 0.95.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/eac_webapp_base0/instance.rb +5 -2
  3. data/lib/avm/eac_webapp_base0/instance/subcommand_parent.rb +24 -0
  4. data/lib/avm/eac_webapp_base0/runner/data.rb +1 -0
  5. data/lib/avm/eac_webapp_base0/runner/data/dump.rb +1 -1
  6. data/lib/avm/eac_webapp_base0/runner/data/load.rb +1 -1
  7. data/lib/avm/git/auto_commit/commit_info.rb +2 -1
  8. data/lib/avm/git/auto_commit/rules.rb +4 -4
  9. data/lib/avm/git/auto_commit/rules/new.rb +24 -0
  10. data/lib/avm/git/auto_commit/rules/nth.rb +8 -0
  11. data/lib/avm/git/auto_commit_path.rb +0 -21
  12. data/lib/avm/git/file_auto_fixup.rb +19 -3
  13. data/lib/avm/ruby/bundler.rb +11 -0
  14. data/lib/avm/ruby/bundler/incompatible_parser.rb +25 -0
  15. data/lib/avm/ruby/bundler/incompatible_parser/depends_on.rb +25 -0
  16. data/lib/avm/ruby/bundler/incompatible_parser/gem_conflict.rb +39 -0
  17. data/lib/avm/ruby/bundler/incompatible_parser/in_gemfile.rb +19 -0
  18. data/lib/avm/ruby/bundler/incompatible_parser/line_buffer.rb +73 -0
  19. data/lib/avm/ruby/bundler/incompatible_parser/line_factory.rb +31 -0
  20. data/lib/avm/ruby/bundler/incompatible_parser/line_parser_base.rb +19 -0
  21. data/lib/avm/ruby/bundler/incompatible_parser/version_requirement.rb +26 -0
  22. data/lib/avm/ruby/gems/generator.rb +1 -5
  23. data/lib/avm/tools/runner/eac_redmine_base0/core_update.rb +7 -11
  24. data/lib/avm/tools/runner/git/auto_commit.rb +28 -28
  25. data/lib/avm/tools/runner/git/subrepo/fix.rb +1 -1
  26. data/lib/avm/tools/runner/local_project/ruby.rb +2 -6
  27. data/lib/avm/tools/runner/local_project/ruby/bundler.rb +3 -7
  28. data/lib/avm/tools/runner/local_project/ruby/bundler/gemfile_lock.rb +10 -13
  29. data/lib/avm/tools/runner/local_project/ruby/bundler/incompatible.rb +84 -0
  30. data/lib/avm/tools/version.rb +1 -1
  31. data/template/avm/ruby/gems/generator/static/spec/rubocop_spec.rb +1 -5
  32. data/template/avm/ruby/gems/generator/static/spec/spec_helper.rb +2 -0
  33. data/vendor/avm-apps/avm-apps.gemspec +1 -1
  34. data/vendor/avm-apps/lib/avm/apps/version.rb +1 -1
  35. data/vendor/avm-apps/spec/rubocop_spec.rb +1 -5
  36. data/vendor/avm-apps/spec/spec_helper.rb +3 -0
  37. data/vendor/eac_cli/eac_cli.gemspec +1 -1
  38. data/vendor/eac_cli/lib/eac_cli/core_ext.rb +2 -0
  39. data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +5 -1
  40. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +3 -1
  41. data/vendor/eac_cli/lib/eac_cli/parser/alternative/short_options.rb +4 -2
  42. data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +2 -1
  43. data/vendor/eac_cli/lib/eac_cli/runner/context.rb +2 -1
  44. data/vendor/eac_cli/lib/eac_cli/runner/instance_methods.rb +8 -1
  45. data/vendor/eac_cli/lib/eac_cli/runner_with_set.rb +50 -0
  46. data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
  47. data/vendor/eac_cli/spec/rubocop_spec.rb +1 -5
  48. data/vendor/eac_cli/spec/spec_helper.rb +3 -0
  49. data/vendor/eac_docker/eac_docker.gemspec +1 -1
  50. data/vendor/eac_docker/lib/eac_docker/version.rb +1 -1
  51. data/vendor/eac_docker/spec/rubocop_spec.rb +1 -5
  52. data/vendor/eac_docker/spec/spec_helper.rb +3 -0
  53. data/vendor/eac_git/eac_git.gemspec +2 -1
  54. data/vendor/eac_git/lib/eac_git/local.rb +4 -0
  55. data/vendor/eac_git/lib/eac_git/local/commit.rb +53 -0
  56. data/vendor/eac_git/lib/eac_git/local/commit/changed_file.rb +46 -0
  57. data/vendor/eac_git/lib/eac_git/local/commit/diff_tree_line.rb +32 -0
  58. data/vendor/eac_git/lib/eac_git/local/dirty_files.rb +2 -3
  59. data/vendor/eac_git/lib/eac_git/rspec.rb +6 -1
  60. data/{lib/avm/git/spec_helper.rb → vendor/eac_git/lib/eac_git/rspec/stubbed_git_local_repo.rb} +16 -13
  61. data/vendor/eac_git/lib/eac_git/version.rb +1 -1
  62. data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec.rb +13 -0
  63. data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/add.source.out +1 -0
  64. data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/add.target.yaml +7 -0
  65. data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/modify.source.out +1 -0
  66. data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/modify.target.yaml +7 -0
  67. data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/remove.source.out +1 -0
  68. data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/remove.target.yaml +7 -0
  69. data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/rename.source.out +2 -0
  70. data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/rename.target.yaml +13 -0
  71. data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/rename_modify.source.out +2 -0
  72. data/vendor/eac_git/spec/lib/eac_git/local/commit/diff_tree_line_spec_files/rename_modify.target.yaml +13 -0
  73. data/vendor/eac_git/spec/lib/eac_git/local/commit_spec.rb +58 -0
  74. data/vendor/eac_git/spec/rubocop_spec.rb +1 -5
  75. data/vendor/eac_git/spec/spec_helper.rb +3 -0
  76. data/vendor/eac_ruby_base0/eac_ruby_base0.gemspec +4 -4
  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/input.rb +36 -0
  88. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner_with/output.rb +58 -0
  89. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
  90. data/vendor/eac_ruby_base0/spec/lib/eac_ruby_base0/runner_with/confirmation_spec.rb +42 -0
  91. data/vendor/eac_ruby_base0/spec/lib/eac_ruby_base0/runner_with/output_spec.rb +81 -0
  92. data/vendor/eac_ruby_base0/spec/rubocop_spec.rb +1 -5
  93. data/vendor/eac_ruby_base0/spec/spec_helper.rb +3 -0
  94. data/vendor/eac_ruby_gems_utils/eac_ruby_gems_utils.gemspec +1 -1
  95. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/base.rb +7 -10
  96. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/multiple.rb +9 -2
  97. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/version.rb +1 -1
  98. data/vendor/eac_ruby_gems_utils/spec/code/rubocop_check_spec.rb +1 -5
  99. data/vendor/eac_ruby_gems_utils/spec/spec_helper.rb +3 -0
  100. data/vendor/eac_ruby_utils/eac_ruby_utils.gemspec +2 -1
  101. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/filesystem_cache.rb +6 -0
  102. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/logs.rb +63 -0
  103. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb +9 -1
  104. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/list.rb +3 -2
  105. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/local_time_zone.rb +8 -2
  106. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/class/settings_provider.rb +10 -0
  107. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/kernel/nyi.rb +4 -2
  108. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_nil.rb +17 -0
  109. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/regexp/to_parser.rb +10 -0
  110. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string/inflector.rb +4 -2
  111. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/required_zone.rb +11 -0
  112. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/regexp_parser.rb +34 -0
  113. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/settings_provider.rb +10 -29
  114. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/settings_provider/setting_value.rb +69 -0
  115. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/simple_cache.rb +18 -5
  116. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  117. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/settings_provider_spec.rb +8 -0
  118. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/simple_cache_spec.rb +9 -0
  119. data/vendor/eac_ruby_utils/spec/rubocop_check_spec.rb +1 -5
  120. data/vendor/eac_ruby_utils/spec/spec_helper.rb +3 -0
  121. metadata +55 -15
  122. data/lib/avm/tools/runner/git/auto_fixup.rb +0 -53
  123. data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +0 -30
  124. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb +0 -53
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'eac_ruby_utils/abstract_methods'
6
+
7
+ module EacRubyBase0
8
+ module RunnerWith
9
+ module Input
10
+ STDIN_OPTION = '-'
11
+ BLANK_OPTION = '+'
12
+ DEFAULT_DEFAULT_INPUT_OPTION = BLANK_OPTION
13
+
14
+ common_concern do
15
+ enable_settings_provider
16
+ include ::EacCli::Runner
17
+
18
+ runner_definition do
19
+ arg_opt '-i', '--input', 'Input from file.'
20
+ end
21
+ end
22
+
23
+ def input_content
24
+ case input_option
25
+ when STDIN_OPTION then $stdin.read
26
+ when BLANK_OPTION then ''
27
+ else input_option.to_pathname.read
28
+ end
29
+ end
30
+
31
+ def input_option
32
+ parsed.input || setting_value(:default_input_option, default: DEFAULT_DEFAULT_INPUT_OPTION)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'eac_ruby_utils/abstract_methods'
6
+
7
+ module EacRubyBase0
8
+ module RunnerWith
9
+ module Output
10
+ STDOUT_OPTION = '-'
11
+ DEFAULT_FILE_OPTION = '+'
12
+ DEFAULT_DEFAULT_OUTPUT_OPTION = STDOUT_OPTION
13
+ DEFAULT_DEFAULT_FILE_TO_OUTPUT = 'output'
14
+
15
+ common_concern do
16
+ enable_abstract_methods
17
+ enable_settings_provider
18
+ include ::EacCli::Runner
19
+
20
+ abstract_methods :output_content
21
+
22
+ runner_definition do
23
+ arg_opt '-o', '--output', 'Output to file.'
24
+ end
25
+ end
26
+
27
+ def run_output
28
+ file = file_to_output
29
+ if file
30
+ file.to_pathname.write(output_content)
31
+ else
32
+ $stdout.write(output_content)
33
+ end
34
+ end
35
+
36
+ def output_option
37
+ parsed.output || default_output_option_value
38
+ end
39
+
40
+ def file_to_output
41
+ case output_option
42
+ when STDOUT_OPTION then nil
43
+ when DEFAULT_FILE_OPTION then default_file_to_output_value
44
+ else output_option
45
+ end
46
+ end
47
+
48
+ def default_output_option_value
49
+ setting_value(:default_output_option,
50
+ default: DEFAULT_DEFAULT_OUTPUT_OPTION)
51
+ end
52
+
53
+ def default_file_to_output_value
54
+ setting_value(:default_file_to_output, default: DEFAULT_DEFAULT_FILE_TO_OUTPUT)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyBase0
4
- VERSION = '0.3.3'
4
+ VERSION = '0.7.1'
5
5
  end
@@ -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
- require 'eac_ruby_gem_support/spec/examples/rubocop_check'
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
@@ -25,5 +25,5 @@ Gem::Specification.new do |s|
25
25
  s.add_dependency 'eac_ruby_utils', '~> 0.29'
26
26
 
27
27
  # Tests
28
- s.add_development_dependency 'eac_ruby_gem_support', '~> 0.1'
28
+ s.add_development_dependency 'eac_ruby_gem_support', '~> 0.2'
29
29
  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.1'
5
5
  end
@@ -1,7 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_gem_support/spec/examples/rubocop_check'
4
-
5
- RSpec.describe ::RuboCop 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
@@ -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.1', '>= 0.1.1'
24
+ s.add_development_dependency 'eac_ruby_gem_support', '~> 0.2'
24
25
  end
@@ -24,6 +24,12 @@ module EacRubyUtils
24
24
  ::File.read(content_path)
25
25
  end
26
26
 
27
+ def read_or_cache
28
+ write(yield) unless cached?
29
+
30
+ read
31
+ end
32
+
27
33
  def write(value)
28
34
  assert_directory_on_path
29
35
  ::File.write(content_path, value)
@@ -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