Class: SiteMaps::Adapters::FileSystem::Storage
- Inherits:
-
Object
- Object
- SiteMaps::Adapters::FileSystem::Storage
- Defined in:
- lib/site_maps/adapters/file_system/storage.rb
Instance Method Summary collapse
- #delete(location) ⇒ void
-
#read(location) ⇒ Array<String, Hash>
The raw data and metadata.
- #write(location, raw_data) ⇒ void
Instance Method Details
#delete(location) ⇒ void
This method returns an undefined value.
43 44 45 46 47 |
# File 'lib/site_maps/adapters/file_system/storage.rb', line 43 def delete(location) File.delete(location.path) rescue Errno::ENOENT raise SiteMaps::FileNotFoundError.new("File not found: #{location.path}") end |
#read(location) ⇒ Array<String, Hash>
Returns The raw data and metadata.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/site_maps/adapters/file_system/storage.rb', line 28 def read(location) if location.gzip? [Zlib::GzipReader.open(location.path).read, {content_type: "application/gzip"}] else [File.read(location.path), {content_type: "application/xml"}] end rescue Zlib::GzipFile::Error raise SiteMaps::FileNotFoundError.new("File not found: #{location.path}") rescue Errno::ENOENT raise SiteMaps::FileNotFoundError.new("File not found: #{location.path}") end |
#write(location, raw_data) ⇒ void
This method returns an undefined value.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/site_maps/adapters/file_system/storage.rb', line 8 def write(location, raw_data, **) dir = location.directory if !File.exist?(dir) FileUtils.mkdir_p(dir) elsif !File.directory?(dir) raise SiteMaps::Error.new("The path #{dir} is not a directory") end stream = File.open(location.path, "wb") if location.gzip? gzip(stream, raw_data) else plain(stream, raw_data) end end |