Module: Storage::Strategies::FileSystem

Extended by:
FileSystem
Included in:
FileSystem
Defined in:
lib/storage/strategies/file_system.rb

Instance Method Summary collapse

Instance Method Details

#fullpath(file) ⇒ Object



10
11
12
# File 'lib/storage/strategies/file_system.rb', line 10

def fullpath(file)
  File.expand_path 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.expand_path(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, options = {})
  prepare!
  file = File.open(file, "rb") unless file.respond_to?(:read) && !file.kind_of?(Pathname)
  path = fullpath(options[:name])

  raise Storage::FileAlreadyExistsError if File.file?(path)

  File.open(path, "wb") do |handler|
    while line = file.gets
      handler.write line
    end
  end
end