Class: Attached::Storage::Base
- Inherits:
-
Object
- Object
- Attached::Storage::Base
- Defined in:
- lib/attached/storage/base.rb
Instance Method Summary collapse
-
#destroy(path) ⇒ Object
Destroy a file at a given path (abstract).
-
#host ⇒ Object
Access the host for a storage service or return null if local.
-
#initialize(credentials = nil) ⇒ Base
constructor
Create a new file system storage interface supporting save and destroy operations.
-
#options(path) ⇒ Object
Helper for determining options from a file.
-
#parse(credentials) ⇒ Object
Helper for parsing credentials from a hash, file, or string.
-
#retrieve(path) ⇒ Object
Retrieve a file from a given path.
-
#save(file, path) ⇒ Object
Save a file to a given path (abstract).
Constructor Details
Instance Method Details
#destroy(path) ⇒ Object
Destroy a file at a given path (abstract).
Parameters:
-
path - The path to destroy.
108 109 110 |
# File 'lib/attached/storage/base.rb', line 108 def destroy(path) raise NotImplementedError.new end |
#host ⇒ Object
Access the host for a storage service or return null if local.
Usage:
storage.host
77 78 79 |
# File 'lib/attached/storage/base.rb', line 77 def host() raise NotImplementedError.new end |
#options(path) ⇒ Object
Helper for determining options from a file
Usage:
("/images/1.jpg")
("/images/1.png")
("/videos/1.mpg")
("/videos/1.mov")
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/attached/storage/base.rb', line 31 def (path) = {} [:content_type] = case File.extname(path) when /tiff/ then "image/tiff" when /tif/ then "image/tiff" when /jpeg/ then "image/jpeg" when /jpe/ then "image/jpeg" when /jpg/ then "image/jpeg" when /png/ then "image/png" when /gif/ then "image/gif" when /bmp/ then "image/bmp" when /mpeg/ then "video/mpeg" when /mpa/ then "video/mpeg" when /mpe/ then "video/mpeg" when /mpg/ then "video/mpeg" when /mov/ then "video/mov" when /josn/ then "application/json" when /xml/ then "application/xml" when /pdf/ then "application/pdf" when /rtf/ then "application/rtf" when /zip/ then "application/zip" when /js/ then "application/js" when /html/ then "text/html" when /html/ then "text/htm" when /txt/ then "text/plain" when /csv/ then "text/csv" end return end |
#parse(credentials) ⇒ Object
Helper for parsing credentials from a hash, file, or string.
Usage:
parse({...})
parse(File.open(...))
Parse("...")
13 14 15 16 17 18 19 20 |
# File 'lib/attached/storage/base.rb', line 13 def parse(credentials) case credentials when Hash then credentials when File then YAML::load(ERB.new(credentials).result)[Rails.env] when String then YAML::load(ERB.new(File.read(credentials)).result)[Rails.env] else raise ArgumentError.new("credentials must be a hash, file, or string") end end |
#retrieve(path) ⇒ Object
Retrieve a file from a given path.
Parameters:
-
path - The path to retrieve.
98 99 100 |
# File 'lib/attached/storage/base.rb', line 98 def retrieve(path) raise NotImplementedError.new end |
#save(file, path) ⇒ Object
Save a file to a given path (abstract).
Parameters:
-
file - The file to save.
-
path - The path to save.
88 89 90 |
# File 'lib/attached/storage/base.rb', line 88 def save(file, path) raise NotImplementedError.new end |