Class: EnMasse::Dragonfly::MogileFS::DataStore

Inherits:
Object
  • Object
show all
Includes:
Dragonfly::Configurable
Defined in:
lib/dragonfly-mogilefs/data_store.rb

Instance Method Summary collapse

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(options = {})
  self.hosts = options[:hosts]
  self.domain = options[:domain]
  self.klass = options[:klass] if options[:klass]
  self.timeout = options[:timeout] if options[:timeout]
  self.readonly = options[:readonly] if options[:readonly]
  self.db_backend = options[:db_backend] if options[:db_backend]
  self.remote_url = options[:remote_url] if options[:remote_url]
end

Instance Method Details

#connectionObject



77
78
79
80
81
82
83
84
85
86
# File 'lib/dragonfly-mogilefs/data_store.rb', line 77

def connection
  options = {
    :hosts => self.hosts,
    :domain => self.domain
  }
  options[:timeout] = self.timeout if self.timeout
  options[:readonly] = self.readonly if self.readonly
  options[:db_backend] = self.db_backend if self.db_backend
  @connection ||= ::MogileFS::MogileFS.new(options)
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, options = {})
  meta = options[:meta] || {}
  uid = options[:key] || generate_uid(meta[: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, meta)
  
  uid
end

#url_for(uid, options = {}) ⇒ Object



88
89
90
# File 'lib/dragonfly-mogilefs/data_store.rb', line 88

def url_for(uid, options = {})
  "#{remote_url}/#{uid}"
end