Class: Attached::Storage::Local
- Defined in:
- lib/attached/storage/local.rb
Instance Attribute Summary collapse
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
Instance Method Summary collapse
-
#destroy(path) ⇒ Object
Destroy a file at a given path.
-
#host ⇒ Object
Access the host (e.g. /system/) for a storage service.
-
#initialize ⇒ Local
constructor
Create a new interface supporting save and destroy operations.
-
#retrieve(path) ⇒ Object
Retrieve a file from a given path.
-
#save(file, path) ⇒ Object
Save a file to a given path.
Methods inherited from Base
Constructor Details
Instance Attribute Details
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
7 8 9 |
# File 'lib/attached/storage/local.rb', line 7 def mode @mode end |
Instance Method Details
#destroy(path) ⇒ Object
Destroy a file at a given path.
Parameters:
-
path - The path to destroy.
65 66 67 68 69 70 71 72 |
# File 'lib/attached/storage/local.rb', line 65 def destroy(path) path = "#{Rails.root}/public/system/#{path}" dirname, basename = File.split(path) begin FileUtils.rm(path) rescue Errno::ENOENT end end |
#host ⇒ Object
Access the host (e.g. /system/) for a storage service.
Usage:
storage.host
25 26 27 |
# File 'lib/attached/storage/local.rb', line 25 def host() "/system/" end |
#retrieve(path) ⇒ Object
Retrieve a file from a given path.
Parameters:
-
path - The path to retrieve.
54 55 56 57 |
# File 'lib/attached/storage/local.rb', line 54 def retrieve(path) path = "#{Rails.root}/public/system/#{path}" File.open(path) end |
#save(file, path) ⇒ Object
Save a file to a given path.
Parameters:
-
file - The file to save.
-
path - The path to save.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/attached/storage/local.rb', line 36 def save(file, path) path = "#{Rails.root}/public/system/#{path}" dirname, basename = File.split(path) return if file.path == path begin FileUtils.mkdir_p(dirname) FileUtils.cp(file.path, path) FileUtils.chmod(self.mode, path) rescue Errno::ENOENT end end |