Module: Conduit::Storage::File::ClassMethods

Defined in:
lib/conduit/storage/file.rb

Instance Method Summary collapse

Instance Method Details

#delete(key) ⇒ Object

Delete a file

e.g.

> Conduit::Storage.delete(‘/path/to/file’)



62
63
64
65
66
# File 'lib/conduit/storage/file.rb', line 62

def delete(key)
  ::File.delete(storage_path.join(key))
rescue Errno::ENOENT, Errno::EPERM
  nil
end

#read(key) ⇒ Object

Read a file

e.g.

> Conduit::Storage.read(‘/path/to/file’)



51
52
53
54
55
# File 'lib/conduit/storage/file.rb', line 51

def read(key)
  ::File.read(storage_path.join(key.to_s))
rescue Errno::ENOENT
  nil
end

#storage_pathObject

Return a Pathname object for the configured file path



28
29
30
# File 'lib/conduit/storage/file.rb', line 28

def storage_path
  @storage_path ||= Pathname.new(config[:file_path])
end

#write(key, content) ⇒ Object

Write a file to AWS::S3

e.g.

> Conduit::Storage.write(‘/path/to/file’, ‘foo’)



37
38
39
40
41
42
43
44
# File 'lib/conduit/storage/file.rb', line 37

def write(key, content)
  full_path = storage_path.join(key)
  FileUtils.mkdir_p(::File.dirname(full_path))

  ::File.open(full_path, "wb") do |f|
    f.write(content)
  end
end