Class: Thumbo::Mogilefs

Inherits:
AbstractStorage show all
Defined in:
lib/thumbo/storages/mogilefs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractStorage

#exist?

Constructor Details

#initialize(opts = {}) ⇒ Mogilefs

Returns a new instance of Mogilefs.



13
14
15
16
17
18
# File 'lib/thumbo/storages/mogilefs.rb', line 13

def initialize opts = {}
  @klass  = opts[:klass]  || 'thumbo'
  @domain = opts[:domain] || 'thumbo'
  @hosts  = opts[:hosts]  || ['127.0.0.1:6001']
  @timeout_time = opts[:timeout_time] || 2
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



12
13
14
# File 'lib/thumbo/storages/mogilefs.rb', line 12

def client
  @client
end

#domainObject

Returns the value of attribute domain.



11
12
13
# File 'lib/thumbo/storages/mogilefs.rb', line 11

def domain
  @domain
end

#hostsObject

Returns the value of attribute hosts.



11
12
13
# File 'lib/thumbo/storages/mogilefs.rb', line 11

def hosts
  @hosts
end

#klassObject

Returns the value of attribute klass.



11
12
13
# File 'lib/thumbo/storages/mogilefs.rb', line 11

def klass
  @klass
end

#timeout_timeObject

Returns the value of attribute timeout_time.



11
12
13
# File 'lib/thumbo/storages/mogilefs.rb', line 11

def timeout_time
  @timeout_time
end

Instance Method Details

#delete(filename) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/thumbo/storages/mogilefs.rb', line 32

def delete filename
  client.delete(filename)

rescue MogileFS::Backend::UnknownKeyError
  raise_file_not_found(filename)

end

#paths(filename) ⇒ Object

raises MogileFS::Backend::UnknownKeyError



41
42
43
44
45
46
47
# File 'lib/thumbo/storages/mogilefs.rb', line 41

def paths filename
  client.get_paths(filename)

rescue MogileFS::Backend::UnknownKeyError
  raise_file_not_found(filename)

end

#read(filename) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/thumbo/storages/mogilefs.rb', line 20

def read filename
  client.get_file_data(filename)

rescue MogileFS::Backend::UnknownKeyError
  raise_file_not_found(filename)

end

#write(filename, blob) ⇒ Object



28
29
30
# File 'lib/thumbo/storages/mogilefs.rb', line 28

def write filename, blob
  client.store_content(filename, klass, blob)
end