Module: Storage::Strategies::FileSystem
Instance Method Summary collapse
- #fullpath(file) ⇒ Object
- #get(file, *noop) ⇒ Object
- #prepare! ⇒ Object
- #remove(file, *noop) ⇒ Object
- #store(file, options = {}) ⇒ Object
Instance Method Details
#fullpath(file) ⇒ Object
10 11 12 |
# File 'lib/storage/strategies/file_system.rb', line 10 def fullpath(file) File. File.join(Storage::Config.path, file) end |
#get(file, *noop) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/storage/strategies/file_system.rb', line 14 def get(file, *noop) prepare! path = fullpath(file) raise Storage::MissingFileError unless File.file?(path) path end |
#prepare! ⇒ Object
6 7 8 |
# File 'lib/storage/strategies/file_system.rb', line 6 def prepare! FileUtils.mkdir_p File.(Storage::Config.path) end |
#remove(file, *noop) ⇒ Object
21 22 23 24 25 |
# File 'lib/storage/strategies/file_system.rb', line 21 def remove(file, *noop) prepare! path = get(file) File.unlink(path) end |
#store(file, options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/storage/strategies/file_system.rb', line 27 def store(file, = {}) prepare! file = File.open(file, "rb") unless file.respond_to?(:read) && !file.kind_of?(Pathname) path = fullpath([:name]) raise Storage::FileAlreadyExistsError if File.file?(path) File.open(path, "wb") do |handler| while line = file.gets handler.write line end end end |