ehbrs-tools 0.6.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs/executables.rb +7 -1
  3. data/lib/ehbrs/fs.rb +9 -0
  4. data/lib/ehbrs/fs/compressed_package.rb +48 -0
  5. data/lib/ehbrs/gems.rb +37 -0
  6. data/lib/ehbrs/google.rb +9 -0
  7. data/lib/ehbrs/google/translate.rb +11 -0
  8. data/lib/ehbrs/google/translate/session.rb +61 -0
  9. data/lib/ehbrs/observers.rb +11 -0
  10. data/lib/ehbrs/observers/base.rb +64 -0
  11. data/lib/ehbrs/observers/with_persistence.rb +34 -0
  12. data/lib/ehbrs/runner/fs.rb +19 -0
  13. data/lib/ehbrs/runner/fs/used_space.rb +161 -0
  14. data/lib/ehbrs/runner/google.rb +19 -0
  15. data/lib/ehbrs/runner/google/translate.rb +92 -0
  16. data/lib/ehbrs/runner/self.rb +19 -0
  17. data/lib/ehbrs/runner/self/test.rb +30 -0
  18. data/lib/ehbrs/runner/videos/extract.rb +71 -0
  19. data/lib/ehbrs/runner/videos/series.rb +21 -0
  20. data/lib/ehbrs/runner/videos/series/rename.rb +75 -0
  21. data/lib/ehbrs/self.rb +9 -0
  22. data/lib/ehbrs/self/observers/used_space.rb +22 -0
  23. data/lib/ehbrs/self/observers/with_persistence.rb +38 -0
  24. data/lib/ehbrs/tools/version.rb +1 -1
  25. data/lib/ehbrs/user_dirs.rb +34 -0
  26. data/lib/ehbrs/vg/wii/game_file.rb +13 -0
  27. data/lib/ehbrs/videos/extract.rb +11 -0
  28. data/lib/ehbrs/videos/extract/package.rb +75 -0
  29. data/lib/ehbrs/videos/extract/package_file.rb +54 -0
  30. data/lib/ehbrs/videos/series.rb +11 -0
  31. data/lib/ehbrs/videos/series/rename.rb +13 -0
  32. data/lib/ehbrs/videos/series/rename/directory_group.rb +28 -0
  33. data/lib/ehbrs/videos/series/rename/file.rb +114 -0
  34. data/lib/ehbrs/videos/series/rename/file/basename_parser.rb +44 -0
  35. data/lib/ehbrs/videos/series/rename/file/options.rb +30 -0
  36. data/lib/ehbrs/videos/series/rename/line_result.rb +26 -0
  37. data/lib/ehbrs/videos/series/rename/line_result_group.rb +39 -0
  38. data/lib/ehbrs/videos/series/rename/results_builder.rb +32 -0
  39. data/lib/ehbrs/videos/series/rename/season_group.rb +39 -0
  40. data/vendor/aranha-selenium/Gemfile +5 -0
  41. data/vendor/aranha-selenium/aranha-selenium.gemspec +19 -0
  42. data/vendor/aranha-selenium/lib/aranha/selenium.rb +8 -0
  43. data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory.rb +47 -0
  44. data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/base.rb +76 -0
  45. data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/chrome.rb +28 -0
  46. data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/firefox.rb +54 -0
  47. data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/firefox_auto_download_mime_types +685 -0
  48. data/vendor/aranha-selenium/lib/aranha/selenium/session.rb +78 -0
  49. data/vendor/aranha-selenium/lib/aranha/selenium/version.rb +7 -0
  50. data/vendor/aranha-selenium/spec/rubocop_check_spec.rb +7 -0
  51. data/vendor/aranha-selenium/spec/spec_helper.rb +100 -0
  52. data/vendor/eac_ruby_utils/eac_ruby_utils.gemspec +1 -1
  53. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +68 -0
  54. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs.rb +4 -12
  55. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +1 -1
  56. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb +1 -1
  57. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/speaker.rb +1 -1
  58. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/executable.rb +2 -2
  59. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/extname.rb +30 -0
  60. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/temp.rb +27 -8
  61. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/temp/directory.rb +16 -0
  62. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/temp/file.rb +34 -0
  63. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/list.rb +4 -0
  64. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/lists.rb +10 -12
  65. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/symbol_list.rb +19 -0
  66. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerable.rb +4 -0
  67. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerable/boolean_combinations.rb +45 -0
  68. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/common_concern.rb +10 -0
  69. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/patch.rb +1 -1
  70. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/require_sub.rb +2 -2
  71. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb +1 -1
  72. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/regexp.rb +4 -0
  73. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/regexp/if_match.rb +16 -0
  74. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time.rb +4 -0
  75. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/default_time_zone_set.rb +5 -0
  76. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb +25 -0
  77. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +1 -3
  78. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/require_sub.rb +45 -2
  79. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  80. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +85 -2
  81. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +42 -0
  82. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +1 -0
  83. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/docopt_runner_spec.rb +5 -5
  84. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/speaker_spec.rb +1 -1
  85. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/executable_spec.rb +4 -0
  86. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/extname_spec.rb +18 -0
  87. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/temp/temp_spec.rb +12 -0
  88. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/{temp.rb → temp_spec.rb} +22 -0
  89. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/listable_spec.rb +32 -0
  90. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb +1 -1
  91. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerable/boolean_combinations_spec.rb +39 -0
  92. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/hash/sym_keys_hash_spec.rb +1 -1
  93. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/if_present_spec.rb +1 -1
  94. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/template_spec.rb +1 -1
  95. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/pathname/basename_sub_spec.rb +4 -4
  96. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec.rb +19 -0
  97. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec/stubbed_module_a.rb +6 -0
  98. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec/stubbed_not_module.rb +6 -0
  99. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/searcher_spec.rb +1 -1
  100. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/yaml_spec.rb +75 -0
  101. data/vendor/eac_ruby_utils/spec/locales/pt-BR.yml +17 -0
  102. metadata +105 -3
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aranha/selenium/driver_factory'
4
+
5
+ module Aranha
6
+ module Selenium
7
+ class Session < ::SimpleDelegator
8
+ attr_reader :downloads, :wait
9
+
10
+ def initialize(options = {})
11
+ @downloads = Downloads.new
12
+ @wait = ::Selenium::WebDriver::Wait.new(timeout: 15)
13
+ super(
14
+ ::Aranha::Selenium::DriverFactory.create_driver(
15
+ options.merge(download_dir: @downloads.dir)
16
+ )
17
+ )
18
+ end
19
+
20
+ def find_or_not_element(find_element_args)
21
+ r = find_elements(find_element_args)
22
+ r.any? ? r.first : nil
23
+ end
24
+
25
+ def wait_for_click(find_element_args)
26
+ wait.until do
27
+ element = find_element(find_element_args)
28
+ element ? element_click(element) : nil
29
+ end
30
+ end
31
+
32
+ def wait_for_element(find_element_args)
33
+ wait.until { find_element(find_element_args) }
34
+ end
35
+
36
+ def wait_for_download
37
+ initial_downloads = downloads.current
38
+ yield
39
+ new_downloads = []
40
+ wait.until do
41
+ new_downloads = downloads.current - initial_downloads
42
+ new_downloads.any?
43
+ end
44
+ new_downloads.first
45
+ end
46
+
47
+ def current_source
48
+ element = find_element(xpath: '/html[1]')
49
+ raise 'Root element not found' unless element
50
+
51
+ s = element.attribute('innerHTML')
52
+ "<html>\n#{s}\n</html>\n"
53
+ end
54
+
55
+ class Downloads
56
+ attr_reader :dir
57
+
58
+ def initialize
59
+ @dir = ::Dir.mktmpdir
60
+ end
61
+
62
+ def current
63
+ Dir.glob("#{dir}/**/*")
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ def element_click(element)
70
+ element.click
71
+ element
72
+ rescue ::Selenium::WebDriver::Error::ElementClickInterceptedError,
73
+ ::Selenium::WebDriver::Error::ElementNotInteractableError
74
+ nil
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aranha
4
+ module Selenium
5
+ VERSION = '0.1.3'
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
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
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
6
+ # this file to always be loaded, without a need to explicitly require it in any
7
+ # files.
8
+ #
9
+ # Given that it is always loaded, you are encouraged to keep this file as
10
+ # light-weight as possible. Requiring heavyweight dependencies from this file
11
+ # will add to the boot time of your test suite on EVERY test run, even for an
12
+ # individual file that may not need all of that loaded. Instead, consider making
13
+ # a separate helper file that requires the additional dependencies and performs
14
+ # the additional setup, and require it from the spec files that actually need
15
+ # it.
16
+ #
17
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
18
+ RSpec.configure do |config|
19
+ # rspec-expectations config goes here. You can use an alternate
20
+ # assertion/expectation library such as wrong or the stdlib/minitest
21
+ # assertions if you prefer.
22
+ config.expect_with :rspec do |expectations|
23
+ # This option will default to `true` in RSpec 4. It makes the `description`
24
+ # and `failure_message` of custom matchers include text for helper methods
25
+ # defined using `chain`, e.g.:
26
+ # be_bigger_than(2).and_smaller_than(4).description
27
+ # # => "be bigger than 2 and smaller than 4"
28
+ # ...rather than:
29
+ # # => "be bigger than 2"
30
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
31
+ end
32
+
33
+ # rspec-mocks config goes here. You can use an alternate test double
34
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
35
+ config.mock_with :rspec do |mocks|
36
+ # Prevents you from mocking or stubbing a method that does not exist on
37
+ # a real object. This is generally recommended, and will default to
38
+ # `true` in RSpec 4.
39
+ mocks.verify_partial_doubles = true
40
+ end
41
+
42
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
43
+ # have no way to turn it off -- the option exists only for backwards
44
+ # compatibility in RSpec 3). It causes shared context metadata to be
45
+ # inherited by the metadata hash of host groups and examples, rather than
46
+ # triggering implicit auto-inclusion in groups with matching metadata.
47
+ config.shared_context_metadata_behavior = :apply_to_host_groups
48
+
49
+ # The settings below are suggested to provide a good initial experience
50
+ # with RSpec, but feel free to customize to your heart's content.
51
+ # # This allows you to limit a spec run to individual examples or groups
52
+ # # you care about by tagging them with `:focus` metadata. When nothing
53
+ # # is tagged with `:focus`, all examples get run. RSpec also provides
54
+ # # aliases for `it`, `describe`, and `context` that include `:focus`
55
+ # # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
56
+ # config.filter_run_when_matching :focus
57
+ #
58
+ # # Allows RSpec to persist some state between runs in order to support
59
+ # # the `--only-failures` and `--next-failure` CLI options. We recommend
60
+ # # you configure your source control system to ignore this file.
61
+ # config.example_status_persistence_file_path = "spec/examples.txt"
62
+ #
63
+ # # Limits the available syntax to the non-monkey patched syntax that is
64
+ # # recommended. For more details, see:
65
+ # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
66
+ # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
67
+ # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
68
+ # config.disable_monkey_patching!
69
+ #
70
+ # # This setting enables warnings. It's recommended, but in some cases may
71
+ # # be too noisy due to issues in dependencies.
72
+ # config.warnings = true
73
+ #
74
+ # # Many RSpec users commonly either run the entire suite or an individual
75
+ # # file, and it's useful to allow more verbose output when running an
76
+ # # individual spec file.
77
+ # if config.files_to_run.one?
78
+ # # Use the documentation formatter for detailed output,
79
+ # # unless a formatter has already been configured
80
+ # # (e.g. via a command-line flag).
81
+ # config.default_formatter = "doc"
82
+ # end
83
+ #
84
+ # # Print the 10 slowest examples and example groups at the
85
+ # # end of the spec run, to help surface which specs are running
86
+ # # particularly slow.
87
+ # config.profile_examples = 10
88
+ #
89
+ # # Run specs in random order to surface order dependencies. If you find an
90
+ # # order dependency and want to debug it, you can fix the order by providing
91
+ # # the seed, which is printed after each run.
92
+ # # --seed 1234
93
+ # config.order = :random
94
+ #
95
+ # # Seed global randomization in this process using the `--seed` CLI option.
96
+ # # Setting this allows you to use `--seed` to deterministically reproduce
97
+ # # test failures related to randomization by passing the same `--seed` value
98
+ # # as the one that triggered the failure.
99
+ # Kernel.srand config.seed
100
+ end
@@ -20,5 +20,5 @@ Gem::Specification.new do |s|
20
20
  s.add_dependency 'colorize', '~> 0.8.1'
21
21
  s.add_dependency 'docopt', '~> 0.6.1'
22
22
  s.add_dependency 'net-ssh', '~> 4.2'
23
- s.add_development_dependency 'eac_ruby_gem_support', '~> 0.1'
23
+ s.add_development_dependency 'eac_ruby_gem_support', '~> 0.1', '>= 0.1.1'
24
24
  end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/concern'
4
+ require 'eac_ruby_utils/simple_cache'
5
+ require 'eac_ruby_utils/patches/object/if_present'
6
+
7
+ module EacRubyUtils
8
+ class CommonConcern
9
+ CLASS_METHODS_MODULE_NAME = 'ClassMethods'
10
+ INSTANCE_METHODS_MODULE_NAME = 'InstanceMethods'
11
+
12
+ attr_reader :after_callback
13
+
14
+ def initialize(&after_callback)
15
+ @after_callback = after_callback
16
+ end
17
+
18
+ def setup(a_module)
19
+ Setup.new(self, a_module).run
20
+ end
21
+
22
+ class Setup
23
+ include ::EacRubyUtils::SimpleCache
24
+ attr_reader :a_module, :common_constructor
25
+
26
+ def initialize(common_constructor, a_module)
27
+ @common_constructor = common_constructor
28
+ @a_module = a_module
29
+ end
30
+
31
+ def run
32
+ setup = self
33
+ a_module.extend(::ActiveSupport::Concern)
34
+ a_module.included do
35
+ %w[class_methods instance_methods after_callback].each do |suffix|
36
+ setup.send("setup_#{suffix}", self)
37
+ end
38
+ end
39
+ end
40
+
41
+ def setup_class_methods(base)
42
+ class_methods_module.if_present { |v| base.extend v }
43
+ end
44
+
45
+ def setup_instance_methods(base)
46
+ instance_methods_module.if_present { |v| base.include v }
47
+ end
48
+
49
+ def setup_after_callback(base)
50
+ common_constructor.after_callback.if_present do |v|
51
+ base.instance_eval(&v)
52
+ end
53
+ end
54
+
55
+ def class_methods_module_uncached
56
+ a_module.const_get(CLASS_METHODS_MODULE_NAME)
57
+ rescue NameError
58
+ nil
59
+ end
60
+
61
+ def instance_methods_module_uncached
62
+ a_module.const_get(INSTANCE_METHODS_MODULE_NAME)
63
+ rescue NameError
64
+ nil
65
+ end
66
+ end
67
+ end
68
+ end
@@ -20,17 +20,11 @@ module EacRubyUtils
20
20
  load
21
21
  end
22
22
 
23
- def clear
24
- file.clear
25
- end
23
+ delegate :clear, to: :file
26
24
 
27
- def save
28
- file.save
29
- end
25
+ delegate :save, to: :file
30
26
 
31
- def load
32
- file.load
33
- end
27
+ delegate :load, to: :file
34
28
 
35
29
  def []=(entry_key, entry_value)
36
30
  write_entry(entry_key, entry_value)
@@ -48,9 +42,7 @@ module EacRubyUtils
48
42
  file.read(entry_key)
49
43
  end
50
44
 
51
- def autosave?
52
- file.autosave?
53
- end
45
+ delegate :autosave?, to: :file
54
46
 
55
47
  private
56
48
 
@@ -85,7 +85,7 @@ module EacRubyUtils
85
85
  def looped_entry_value_from_input(entry_key, options)
86
86
  loop do
87
87
  entry_value = entry_value_from_input(entry_key, options)
88
- next unless entry_value.present?
88
+ next if entry_value.blank?
89
89
  next if options[:validator] && !options[:validator].call(entry_value)
90
90
 
91
91
  return entry_value
@@ -10,7 +10,7 @@ module EacRubyUtils
10
10
  new(options).send(:run)
11
11
  rescue Docopt::Exit => e
12
12
  STDERR.write(e.message + "\n")
13
- ::Kernel.exit(DOCOPT_ERROR_EXIT_CODE)
13
+ ::Kernel.exit(DOCOPT_ERROR_EXIT_CODE) # rubocop:disable Rails/Exit
14
14
  end
15
15
  end
16
16
  end
@@ -26,7 +26,7 @@ module EacRubyUtils
26
26
 
27
27
  def fatal_error(string)
28
28
  puts "ERROR: #{string}".white.on_red
29
- Kernel.exit 1
29
+ Kernel.exit 1 # rubocop:disable Rails/Exit
30
30
  end
31
31
 
32
32
  def title(string)
@@ -31,9 +31,9 @@ module EacRubyUtils
31
31
  raise ProgramNotFoundError, message if message
32
32
  end
33
33
 
34
- def command
34
+ def command(*command_args)
35
35
  validate!
36
- env.command(name)
36
+ env.command(name, *command_args)
37
37
  end
38
38
 
39
39
  private
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ module Fs
5
+ class << self
6
+ # A [File.extname] which find multiple extensions (Ex.: .tar.gz).
7
+ def extname(path, limit = -1)
8
+ recursive_extension(::File.basename(path), limit)
9
+ end
10
+
11
+ # Shortcut to +extname(2)+.
12
+ def extname2(path)
13
+ extname(path, 2)
14
+ end
15
+
16
+ private
17
+
18
+ def recursive_extension(basename, limit)
19
+ return '' if limit.zero?
20
+
21
+ m = /\A(.+)(\.[a-z][a-z0-9]*)\z/i.match(basename)
22
+ if m
23
+ "#{recursive_extension(m[1], limit - 1)}#{m[2]}"
24
+ else
25
+ ''
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/require_sub'
3
4
  require 'pathname'
4
5
  require 'tempfile'
5
6
 
@@ -8,23 +9,41 @@ module EacRubyUtils
8
9
  # Utilities for temporary files.
9
10
  module Temp
10
11
  class << self
12
+ ::EacRubyUtils.require_sub __FILE__
13
+
14
+ # Shortcut to +EacRubyUtils::Fs::Temp::Directory.new(*tempfile_args)+.
15
+ #
16
+ # @return [Pathname]
17
+ def directory(*tempfile_args)
18
+ ::EacRubyUtils::Fs::Temp::Directory.new(*tempfile_args)
19
+ end
20
+
21
+ # Shortcut to +EacRubyUtils::Fs::Temp::File.new(*tempfile_args)+.
22
+ #
11
23
  # @return [Pathname]
12
24
  def file(*tempfile_args)
13
- file = Tempfile.new(*tempfile_args)
14
- r = ::Pathname.new(file.path)
15
- file.close
16
- file.unlink
17
- r
25
+ ::EacRubyUtils::Fs::Temp::File.new(*tempfile_args)
26
+ end
27
+
28
+ # Run a block while a temporary directory pathname is provided. The directory is deleted
29
+ # when the block is finished.
30
+ def on_directory(*tempfile_args)
31
+ temp_dir = directory(*tempfile_args)
32
+ begin
33
+ yield(temp_dir)
34
+ ensure
35
+ temp_dir.remove
36
+ end
18
37
  end
19
38
 
20
39
  # Run a block while a temporary file pathname is providade. The file is deleted when block
21
40
  # is finished.
22
41
  def on_file(*tempfile_args)
23
- pathname = file(*tempfile_args)
42
+ temp_file = file(*tempfile_args)
24
43
  begin
25
- yield(pathname)
44
+ yield(temp_file)
26
45
  ensure
27
- pathname.unlink if pathname.exist?
46
+ temp_file.remove
28
47
  end
29
48
  end
30
49
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/fs/temp/file'
4
+
5
+ module EacRubyUtils
6
+ module Fs
7
+ module Temp
8
+ class Directory < ::EacRubyUtils::Fs::Temp::File
9
+ def initialize(*tempfile_args)
10
+ super(*tempfile_args)
11
+ mkpath
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end