Module: EacRubyGemSupport::Rspec::Helpers::Filesystem
- Defined in:
- lib/eac_ruby_gem_support/rspec/helpers/filesystem.rb
Instance Method Summary collapse
- #purge_temp_files ⇒ Object
- #temp_copy(source_path) ⇒ Pathname
- #temp_dir(*mktmpdir_args) ⇒ Pathname
- #temp_dir_copy(source_path) ⇒ Pathname
- #temp_file(*tempfile_args) ⇒ Pathname
- #temp_file_copy(source_path) ⇒ Pathname
- #to_pathname(path) ⇒ Pathname
Instance Method Details
#purge_temp_files ⇒ Object
11 12 13 |
# File 'lib/eac_ruby_gem_support/rspec/helpers/filesystem.rb', line 11 def purge_temp_files ::FileUtils.rm_rf(temp_set.pop) while temp_set.any? end |
#temp_copy(source_path) ⇒ Pathname
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/eac_ruby_gem_support/rspec/helpers/filesystem.rb', line 16 def temp_copy(source_path) source_path = to_pathname(source_path) if source_path.file? temp_file_copy(source_path) elsif source_path.directory? temp_dir_copy(source_path) else raise "Source path \"#{source_path}\" is not a file or directory" end end |
#temp_dir(*mktmpdir_args) ⇒ Pathname
28 29 30 |
# File 'lib/eac_ruby_gem_support/rspec/helpers/filesystem.rb', line 28 def temp_dir(*mktmpdir_args) add_to_temp_set(::Dir.mktmpdir(*mktmpdir_args)) end |
#temp_dir_copy(source_path) ⇒ Pathname
33 34 35 36 37 |
# File 'lib/eac_ruby_gem_support/rspec/helpers/filesystem.rb', line 33 def temp_dir_copy(source_path) r = temp_dir ::FileUtils.cp_r("#{source_path}/.", r.to_path) r end |
#temp_file(*tempfile_args) ⇒ Pathname
40 41 42 43 44 45 |
# File 'lib/eac_ruby_gem_support/rspec/helpers/filesystem.rb', line 40 def temp_file(*tempfile_args) file = ::Tempfile.new(*tempfile_args) path = file.path file.close add_to_temp_set(path) end |
#temp_file_copy(source_path) ⇒ Pathname
48 49 50 51 52 |
# File 'lib/eac_ruby_gem_support/rspec/helpers/filesystem.rb', line 48 def temp_file_copy(source_path) r = temp_file ::FileUtils.cp(to_pathname(source_path).to_path, r.to_path) r end |
#to_pathname(path) ⇒ Pathname
55 56 57 |
# File 'lib/eac_ruby_gem_support/rspec/helpers/filesystem.rb', line 55 def to_pathname(path) path.is_a?(::Pathname) ? path : ::Pathname.new(path.to_s) end |