Class: DerivativeRodeo::StorageLocations::FileLocation
- Inherits:
-
BaseLocation
- Object
- BaseLocation
- DerivativeRodeo::StorageLocations::FileLocation
show all
- Defined in:
- lib/derivative_rodeo/storage_locations/file_location.rb
Overview
Location for files found on a local disk
Instance Attribute Summary
Attributes inherited from BaseLocation
#file_uri
Class Method Summary
collapse
Instance Method Summary
collapse
build, #derived_file_from, #file_basename, #file_dir, #file_extension, #file_name, #file_path, file_path_from_parts, from_uri, inherited, #initialize, load_location, location_name, locations, register_location, #tmp_file_dir, #with_new_extension, #with_new_tmp_path, #with_tmp_path
Class Method Details
.adapter_prefix ⇒ Object
13
14
15
|
# File 'lib/derivative_rodeo/storage_locations/file_location.rb', line 13
def self.adapter_prefix
"#{scheme}://"
end
|
.create_uri(path:, parts: :all) ⇒ Object
8
9
10
11
|
# File 'lib/derivative_rodeo/storage_locations/file_location.rb', line 8
def self.create_uri(path:, parts: :all)
file_path = file_path_from_parts(path: path, parts: parts)
"#{adapter_prefix}#{file_path}"
end
|
Instance Method Details
#exist? ⇒ Boolean
25
26
27
|
# File 'lib/derivative_rodeo/storage_locations/file_location.rb', line 25
def exist?
File.exist?(file_path)
end
|
44
45
46
47
48
49
50
51
|
# File 'lib/derivative_rodeo/storage_locations/file_location.rb', line 44
def matching_locations_in_file_dir(tail_regexp:)
logger.debug("#{self.class}##{__method__} searching for matching files in " \
"file_dir: #{file_dir.inspect} " \
"with tail_regexp: #{tail_regexp.inspect}.")
Dir.glob(File.join(file_dir, "*")).each_with_object([]) do |filename, accumulator|
accumulator << derived_file_from(template: "file://#{filename}") if tail_regexp.match(filename)
end
end
|
#with_existing_tmp_path(&block) ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/derivative_rodeo/storage_locations/file_location.rb', line 17
def with_existing_tmp_path(&block)
with_tmp_path(lambda { |file_path, tmp_file_path, exist|
raise Errors::FileMissingError.with_info(method: __method__, context: self, file_path: file_path, tmp_file_path: tmp_file_path) unless exist
FileUtils.cp(file_path, tmp_file_path)
}, &block)
end
|
#write ⇒ Object
write the file to the file_uri
30
31
32
33
34
35
36
|
# File 'lib/derivative_rodeo/storage_locations/file_location.rb', line 30
def write
raise Errors::FileMissingError("Use write within a with_new_tmp_path block and fille the mp file with data before writing") unless File.exist?(tmp_file_path)
FileUtils.mkdir_p(file_dir)
FileUtils.cp_r(tmp_file_path, file_path)
file_uri
end
|