Class: StandardStorage::Filesystem
- Inherits:
-
StandardStorage
- Object
- StandardStorage
- StandardStorage::Filesystem
- Defined in:
- lib/standard_storage/filesystem.rb
Constant Summary
Constants inherited from StandardStorage
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#path(key) ⇒ Object
readonly
Returns the value of attribute path.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Attributes inherited from StandardStorage
Instance Method Summary collapse
- #cp(source, destination) ⇒ Object
- #delete(key) ⇒ Object
- #destination(key) ⇒ Object
- #exists?(key) ⇒ Boolean
-
#initialize(configs = {}) ⇒ Filesystem
constructor
A new instance of Filesystem.
- #last_modified(key) ⇒ Object
- #local? ⇒ Boolean
- #mime_type(key) ⇒ Object
- #read(key, &block) ⇒ Object
- #url(key) ⇒ Object
- #write(key, file, options = {}) ⇒ Object
Methods inherited from StandardStorage
Constructor Details
#initialize(configs = {}) ⇒ Filesystem
Returns a new instance of Filesystem.
8 9 10 11 12 13 |
# File 'lib/standard_storage/filesystem.rb', line 8 def initialize(configs={}) super @host = configs[:host] @path = configs[:path] @prefix = configs[:prefix] end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
6 7 8 |
# File 'lib/standard_storage/filesystem.rb', line 6 def host @host end |
#path(key) ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/standard_storage/filesystem.rb', line 6 def path @path end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
6 7 8 |
# File 'lib/standard_storage/filesystem.rb', line 6 def prefix @prefix end |
Instance Method Details
#cp(source, destination) ⇒ Object
41 42 43 44 |
# File 'lib/standard_storage/filesystem.rb', line 41 def cp(source, destination) source = destination(source) FileUtils.cp(source, destination) end |
#delete(key) ⇒ Object
50 51 52 |
# File 'lib/standard_storage/filesystem.rb', line 50 def delete(key) FileUtils.rm(destination(key), force: true) end |
#destination(key) ⇒ Object
27 28 29 |
# File 'lib/standard_storage/filesystem.rb', line 27 def destination(key) File.join([@path, partition(key)].compact) end |
#exists?(key) ⇒ Boolean
31 32 33 |
# File 'lib/standard_storage/filesystem.rb', line 31 def exists?(key) File.exist?(destination(key)) end |
#last_modified(key) ⇒ Object
54 55 56 |
# File 'lib/standard_storage/filesystem.rb', line 54 def last_modified(key) File.mtime(destination(key)) end |
#local? ⇒ Boolean
15 16 17 |
# File 'lib/standard_storage/filesystem.rb', line 15 def local? true end |
#mime_type(key) ⇒ Object
58 59 60 61 |
# File 'lib/standard_storage/filesystem.rb', line 58 def mime_type(key) command = Terrapin::CommandLine.new("file", '-b --mime-type :file') command.run({ file: destination(key) }).strip end |
#read(key, &block) ⇒ Object
46 47 48 |
# File 'lib/standard_storage/filesystem.rb', line 46 def read(key, &block) File.read(destination(key), &block) end |
#url(key) ⇒ Object
19 20 21 |
# File 'lib/standard_storage/filesystem.rb', line 19 def url(key) File.join([@host, path(key)].compact) end |
#write(key, file, options = {}) ⇒ Object
35 36 37 38 39 |
# File 'lib/standard_storage/filesystem.rb', line 35 def write(key, file, ={}) key = destination(key) FileUtils.mkdir_p(File.dirname(key)) FileUtils.cp(file.path, key) end |