Class: EnMasse::Dragonfly::MogileFS::DataStore
- Inherits:
-
Object
- Object
- EnMasse::Dragonfly::MogileFS::DataStore
- Includes:
- Dragonfly::Configurable
- Defined in:
- lib/dragonfly-mogilefs/data_store.rb
Instance Method Summary collapse
- #connection ⇒ Object
- #destroy(uid) ⇒ Object
-
#initialize(options = {}) ⇒ DataStore
constructor
A new instance of DataStore.
- #retrieve(uid) ⇒ Object
- #store(temp_object, options = {}) ⇒ Object
- #url_for(uid, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ DataStore
Returns a new instance of DataStore.
35 36 37 38 39 40 41 42 43 |
# File 'lib/dragonfly-mogilefs/data_store.rb', line 35 def initialize( = {}) self.hosts = [:hosts] self.domain = [:domain] self.klass = [:klass] if [:klass] self.timeout = [:timeout] if [:timeout] self.readonly = [:readonly] if [:readonly] self.db_backend = [:db_backend] if [:db_backend] self.remote_url = [:remote_url] if [:remote_url] end |
Instance Method Details
#connection ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/dragonfly-mogilefs/data_store.rb', line 77 def connection = { :hosts => self.hosts, :domain => self.domain } [:timeout] = self.timeout if self.timeout [:readonly] = self.readonly if self.readonly [:db_backend] = self.db_backend if self.db_backend @connection ||= ::MogileFS::MogileFS.new() end |
#destroy(uid) ⇒ Object
71 72 73 74 75 |
# File 'lib/dragonfly-mogilefs/data_store.rb', line 71 def destroy(uid) connection.delete(uid) rescue ::MogileFS::Backend::UnknownKeyError => e raise ::Dragonfly::DataStorage::DataNotFound, "#{e} - #{uid}" end |
#retrieve(uid) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/dragonfly-mogilefs/data_store.rb', line 62 def retrieve(uid) [ connection.get_file_data(uid), (uid) ] rescue ::MogileFS::Backend::UnknownKeyError => e raise ::Dragonfly::DataStorage::DataNotFound, "#{e} - #{uid}" end |
#store(temp_object, options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/dragonfly-mogilefs/data_store.rb', line 45 def store(temp_object, = {}) = [:meta] || {} uid = [:key] || generate_uid([:name] || temp_object.original_filename || 'file') if use_filesystem temp_object.file do |fp| connection.store_file(uid, self.klass, fp) end else connection.store_file(uid, self.klass, temp_object.data) end (uid, ) uid end |
#url_for(uid, options = {}) ⇒ Object
88 89 90 |
# File 'lib/dragonfly-mogilefs/data_store.rb', line 88 def url_for(uid, = {}) "#{remote_url}/#{uid}" end |