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’)



64
65
66
67
68
# File 'lib/conduit/storage/file.rb', line 64

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’)



53
54
55
56
57
# File 'lib/conduit/storage/file.rb', line 53

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

#storage_pathObject

Return a Pathname object for the configured file path



30
31
32
# File 'lib/conduit/storage/file.rb', line 30

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’)



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

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

  ::File.open(full_path, 'w') do |f|
    f.write(content)
  end
end