Class: Useless::FS

Inherits:
Object
  • Object
show all
Defined in:
lib/useless/fs.rb

Overview

Useless::FS is a minimal wrapper around Mongo::Grid.

Defined Under Namespace

Classes: FileNotFound

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mongo) ⇒ FS

Returns a new instance of FS.



12
13
14
# File 'lib/useless/fs.rb', line 12

def initialize(mongo)
  @mongo = mongo
end

Class Method Details

.for_env(env = nil) ⇒ Object



7
8
9
10
# File 'lib/useless/fs.rb', line 7

def self.for_env(env = nil)
  mongo = Useless::Mongo.for_env(env)
  self.new(mongo)
end

Instance Method Details

#get(id) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/useless/fs.rb', line 22

def get(id)
  @mongo.grid.get(id)

# To preserve the abstraction, raise our own exception when a file isn't
# found
rescue ::Mongo::GridFileNotFound => e
  raise FileNotFound, e.message
end

#put(file, opts = {}) ⇒ Object



16
17
18
# File 'lib/useless/fs.rb', line 16

def put(file, opts = {})
  @mongo.grid.put(file, opts)
end