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
#initialize ⇒ Local
Create a new interface supporting save and destroy operations.
Usage:
Attached::Storage::Local.new()
17 18 19 |
# File 'lib/attached/storage/local.rb', line 17 def initialize() @mode = 0644 end |
Instance Attribute Details
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
8 9 10 |
# File 'lib/attached/storage/local.rb', line 8 def mode @mode end |
Instance Method Details
#destroy(path) ⇒ Object
Destroy a file at a given path.
Parameters:
-
path - The path to destroy.
74 75 76 77 78 79 80 81 82 |
# File 'lib/attached/storage/local.rb', line 74 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
28 29 30 |
# File 'lib/attached/storage/local.rb', line 28 def host() "/system/" end |
#retrieve(path) ⇒ Object
Retrieve a file from a given path.
Parameters:
-
path - The path to retrieve.
61 62 63 64 65 |
# File 'lib/attached/storage/local.rb', line 61 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.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/attached/storage/local.rb', line 40 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 |