Parent

Included Modules

Files

Class/Module Index [+]

Quicksearch

Dragonfly::DataStorage::FileDataStore

Public Instance Methods

destroy(relative_path) click to toggle source
# File lib/dragonfly/data_storage/file_data_store.rb, line 50
def destroy(relative_path)
  validate_uid!(relative_path)
  path = absolute(relative_path)
  FileUtils.rm path
  FileUtils.rm_f meta_data_path(path)
  FileUtils.rm_f deprecated_meta_data_path(path)
  purge_empty_directories(relative_path)
rescue Errno::ENOENT => e
  raise DataNotFound, e.message
end
disambiguate(path) click to toggle source
# File lib/dragonfly/data_storage/file_data_store.rb, line 74
def disambiguate(path)
  dirname = File.dirname(path)
  basename = File.basename(path, '.*')
  extname = File.extname(path)
  "#{dirname}/#{basename}_#{(Time.now.usec*10 + rand(100)).to_s(32)}#{extname}"
end
retrieve(relative_path) click to toggle source
# File lib/dragonfly/data_storage/file_data_store.rb, line 39
def retrieve(relative_path)
  validate_uid!(relative_path)
  path = absolute(relative_path)
  pathname = Pathname.new(path)
  raise DataNotFound, "couldn't find file #{path}" unless pathname.exist?
  [
    pathname,
    (store_meta ? retrieve_meta_data(path) : {})
  ]
end
store(temp_object, opts={}) click to toggle source
# File lib/dragonfly/data_storage/file_data_store.rb, line 17
def store(temp_object, opts={})
  relative_path = if opts[:path]
    opts[:path]
  else
    filename = temp_object.name || 'file'
    relative_path = relative_path_for(filename)
  end

  begin
    path = absolute(relative_path)
    until !File.exist?(path)
      path = disambiguate(path)
    end
    temp_object.to_file(path).close
    store_meta_data(path, temp_object.meta) if store_meta
  rescue Errno::EACCES => e
    raise UnableToStore, e.message
  end

  relative(path)
end
url_for(relative_path, opts={}) click to toggle source
# File lib/dragonfly/data_storage/file_data_store.rb, line 61
def url_for(relative_path, opts={})
  if server_root.nil?
    raise NotConfigured, "you need to configure server_root for #{self.class.name} in order to form urls"
  else
    _, __, path = absolute(relative_path).partition(server_root)
    if path.empty?
      raise UnableToFormUrl, "couldn't form url for uid #{relative_path.inspect} with root_path #{root_path.inspect} and server_root #{server_root.inspect}"
    else
      path
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.