class SocialAvatarProxy::Configuration

Public Class Methods

new() click to toggle source
# File lib/social_avatar_proxy/configuration.rb, line 9
def initialize
  @memcache = Memcache.new
  @file_cache = FileCache.new
  @http_cache = HttpCache.new
end

Public Instance Methods

caches() click to toggle source

returns a Caches object containing the configured caches

# File lib/social_avatar_proxy/configuration.rb, line 64
def caches
  Caches.new.tap do |set|
    set.push(@memcache) if @memcache.enabled?
    set.push(@file_cache) if @file_cache.enabled?
  end
end
configure(&block) click to toggle source

updates the configuration

# File lib/social_avatar_proxy/configuration.rb, line 16
def configure(&block)
  instance_eval(&block)
end
default_image(value = nil) click to toggle source
# File lib/social_avatar_proxy/configuration.rb, line 71
def default_image(value = nil)
  if value
    unless File.exist?(value) && File.readable?(value)
      raise ArgumentError, "#{value} does not exist, or is unreadable"
    end
    @default_image = value
  end
  @default_image && AvatarFile.new(@default_image).tap do |file|
    file.content_type(default_image_content_type)
  end
end
default_image_content_type(value = nil) click to toggle source
# File lib/social_avatar_proxy/configuration.rb, line 83
def default_image_content_type(value = nil)
  @default_image_content_type = value if value
  [
    @default_image_content_type,
    auto_detect_default_image_content_type,
    "application/octet-stream"
  ].compact.first
end
delivery_method() click to toggle source

returns how the app should serve the file defaults to streaming the file data

# File lib/social_avatar_proxy/configuration.rb, line 59
def delivery_method
  @serve_via ||= :stream
end
file_cache(&block) click to toggle source

configures or retrieves the file cache instance

# File lib/social_avatar_proxy/configuration.rb, line 21
def file_cache(&block)
  if block_given?
    @file_cache.configure(&block)
  else
    @file_cache
  end
end
http_cache(&block) click to toggle source

configures or retrieves the http cache instance

# File lib/social_avatar_proxy/configuration.rb, line 30
def http_cache(&block)
  if block_given?
    @http_cache.configure(&block)
  else
    @http_cache
  end
end
memcache(&block) click to toggle source

configures or retrieves the memcache cache instance

# File lib/social_avatar_proxy/configuration.rb, line 39
def memcache(&block)
  if block_given?
    @memcache.configure(&block)
  else
    @memcache
  end
end
x_accel_redirect() click to toggle source

serves the file via an x_accel_redirect

# File lib/social_avatar_proxy/configuration.rb, line 53
def x_accel_redirect
  serve_via(:x_accel_redirect)
end
x_send_file() click to toggle source

serves the file via a header

# File lib/social_avatar_proxy/configuration.rb, line 48
def x_send_file
  serve_via(:x_send_file)
end

Private Instance Methods

auto_detect_default_image_content_type() click to toggle source
# File lib/social_avatar_proxy/configuration.rb, line 97
def auto_detect_default_image_content_type
  case File.extname(@default_image)
  when ".png"
    "image/png"
  when ".gif"
    "image/gif"
  when ".svg"
    "application/svg+xml"
  when /\.jpe?g/
    "image/jpeg"
  else
    "application/octet-stream"
  end if @default_image
end
serve_via(value) click to toggle source
# File lib/social_avatar_proxy/configuration.rb, line 93
def serve_via(value)
  @serve_via = value
end