lib/dragonfly-mogilefs/data_store.rb in dragonfly-mogilefs-0.0.2 vs lib/dragonfly-mogilefs/data_store.rb in dragonfly-mogilefs-0.0.3

- old
+ new

@@ -28,10 +28,11 @@ configurable_attr :klass, nil configurable_attr :timeout configurable_attr :readonly configurable_attr :db_backend configurable_attr :remote_url + configurable_attr :use_filesystem, true def initialize(options = {}) self.hosts = options[:hosts] self.domain = options[:domain] self.klass = options[:klass] if options[:klass] @@ -42,14 +43,19 @@ end def store(temp_object, options = {}) meta = options[:meta] || {} uid = options[:key] || generate_uid(meta[:name] || temp_object.original_filename || 'file') - - temp_object.file do |fp| - connection.store_file(uid, self.klass, fp) + + 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 + store_meta_data(uid, meta) uid end @@ -77,10 +83,10 @@ options[:readonly] = self.readonly if self.readonly options[:db_backend] = self.db_backend if self.db_backend @connection ||= ::MogileFS::MogileFS.new(options) end - def url_for(uid) + def url_for(uid, options = {}) "#{remote_url}/#{uid}" end private