Class: Thumbo::Mogilefs
- Inherits:
-
AbstractStorage
- Object
- AbstractStorage
- Thumbo::Mogilefs
- Defined in:
- lib/thumbo/storages/mogilefs.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#hosts ⇒ Object
Returns the value of attribute hosts.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#timeout_time ⇒ Object
Returns the value of attribute timeout_time.
Instance Method Summary collapse
- #delete(filename) ⇒ Object
- #exist?(filename) ⇒ Boolean
-
#initialize(opts = {}) ⇒ Mogilefs
constructor
A new instance of Mogilefs.
- #paths(filename) ⇒ Object
- #read(filename) ⇒ Object
- #write(filename, blob) ⇒ Object
- #write_file(filename, file) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Mogilefs
Returns a new instance of Mogilefs.
14 15 16 17 18 19 |
# File 'lib/thumbo/storages/mogilefs.rb', line 14 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
#client ⇒ Object
Returns the value of attribute client.
13 14 15 |
# File 'lib/thumbo/storages/mogilefs.rb', line 13 def client @client end |
#domain ⇒ Object
Returns the value of attribute domain.
12 13 14 |
# File 'lib/thumbo/storages/mogilefs.rb', line 12 def domain @domain end |
#hosts ⇒ Object
Returns the value of attribute hosts.
12 13 14 |
# File 'lib/thumbo/storages/mogilefs.rb', line 12 def hosts @hosts end |
#klass ⇒ Object
Returns the value of attribute klass.
12 13 14 |
# File 'lib/thumbo/storages/mogilefs.rb', line 12 def klass @klass end |
#timeout_time ⇒ Object
Returns the value of attribute timeout_time.
12 13 14 |
# File 'lib/thumbo/storages/mogilefs.rb', line 12 def timeout_time @timeout_time end |
Instance Method Details
#delete(filename) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/thumbo/storages/mogilefs.rb', line 41 def delete filename client.delete(filename) rescue MogileFS::Backend::UnknownKeyError raise_file_not_found(filename) end |
#exist?(filename) ⇒ Boolean
57 58 59 60 61 62 63 |
# File 'lib/thumbo/storages/mogilefs.rb', line 57 def exist? filename target = paths(filename) target[ rand(target.size) ] rescue Thumbo::FileNotFound false end |
#paths(filename) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/thumbo/storages/mogilefs.rb', line 49 def paths filename client.get_paths(filename) rescue MogileFS::Backend::UnknownKeyError raise_file_not_found(filename) end |
#read(filename) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/thumbo/storages/mogilefs.rb', line 21 def read filename Timeout.timeout(timeout_time){ paths(filename).each{ |path| begin return client.get_file_data(filename) rescue SystemCallError next end } } end |
#write(filename, blob) ⇒ Object
33 34 35 |
# File 'lib/thumbo/storages/mogilefs.rb', line 33 def write filename, blob client.store_content(filename, klass, blob) end |
#write_file(filename, file) ⇒ Object
37 38 39 |
# File 'lib/thumbo/storages/mogilefs.rb', line 37 def write_file filename, file client.store_file(filename, klass, file) end |