Module: Storage::Strategies::FileSystem
Instance Method Summary collapse
- #connect! ⇒ Object
- #disconnect! ⇒ Object
- #fullpath(file) ⇒ Object
- #get(file, *noop) ⇒ Object
- #prepare! ⇒ Object
- #remove(file, *noop) ⇒ Object
- #store(file, options = {}) ⇒ Object
Instance Method Details
#connect! ⇒ Object
6 7 |
# File 'lib/storage/strategies/file_system.rb', line 6 def connect! end |
#disconnect! ⇒ Object
9 10 |
# File 'lib/storage/strategies/file_system.rb', line 9 def disconnect! end |
#fullpath(file) ⇒ Object
16 17 18 |
# File 'lib/storage/strategies/file_system.rb', line 16 def fullpath(file) File. File.join(Storage::Config.path, file) end |
#get(file, *noop) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/storage/strategies/file_system.rb', line 20 def get(file, *noop) prepare! path = fullpath(file) raise Storage::MissingFileError unless File.file?(path) path end |
#prepare! ⇒ Object
12 13 14 |
# File 'lib/storage/strategies/file_system.rb', line 12 def prepare! FileUtils.mkdir_p File.(Storage::Config.path) end |
#remove(file, *noop) ⇒ Object
27 28 29 30 31 |
# File 'lib/storage/strategies/file_system.rb', line 27 def remove(file, *noop) prepare! path = get(file) File.unlink(path) end |
#store(file, options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/storage/strategies/file_system.rb', line 33 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 |