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

#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.expand_path 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.expand_path(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, 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