Class: SocialAvatarProxy::Configuration
- Inherits:
-
Object
- Object
- SocialAvatarProxy::Configuration
- Defined in:
- lib/social_avatar_proxy/configuration.rb,
lib/social_avatar_proxy/configuration/cache.rb,
lib/social_avatar_proxy/configuration/caches.rb,
lib/social_avatar_proxy/configuration/memcache.rb,
lib/social_avatar_proxy/configuration/file_cache.rb,
lib/social_avatar_proxy/configuration/http_cache.rb
Defined Under Namespace
Classes: Cache, Caches, FileCache, HttpCache, Memcache
Instance Method Summary collapse
-
#caches ⇒ Object
returns a Caches object containing the configured caches.
-
#configure(&block) ⇒ Object
updates the configuration.
- #default_image(value = nil) ⇒ Object
- #default_image_content_type(value = nil) ⇒ Object
-
#delivery_method ⇒ Object
returns how the app should serve the file defaults to streaming the file data.
-
#file_cache(&block) ⇒ Object
configures or retrieves the file cache instance.
-
#http_cache(&block) ⇒ Object
configures or retrieves the http cache instance.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#memcache(&block) ⇒ Object
configures or retrieves the memcache cache instance.
-
#x_accel_redirect ⇒ Object
serves the file via an x_accel_redirect.
-
#x_send_file ⇒ Object
serves the file via a header.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
9 10 11 12 13 |
# File 'lib/social_avatar_proxy/configuration.rb', line 9 def initialize @memcache = Memcache.new @file_cache = FileCache.new @http_cache = HttpCache.new end |
Instance Method Details
#caches ⇒ Object
returns a Caches object containing the configured caches
64 65 66 67 68 69 |
# 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) ⇒ Object
updates the configuration
16 17 18 |
# File 'lib/social_avatar_proxy/configuration.rb', line 16 def configure(&block) instance_eval(&block) end |
#default_image(value = nil) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# 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) ⇒ Object
83 84 85 86 87 88 89 90 |
# 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 ⇒ Object
returns how the app should serve the file defaults to streaming the file data
59 60 61 |
# File 'lib/social_avatar_proxy/configuration.rb', line 59 def delivery_method @serve_via ||= :stream end |
#file_cache(&block) ⇒ Object
configures or retrieves the file cache instance
21 22 23 24 25 26 27 |
# 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) ⇒ Object
configures or retrieves the http cache instance
30 31 32 33 34 35 36 |
# 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) ⇒ Object
configures or retrieves the memcache cache instance
39 40 41 42 43 44 45 |
# 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 ⇒ Object
serves the file via an x_accel_redirect
53 54 55 |
# File 'lib/social_avatar_proxy/configuration.rb', line 53 def x_accel_redirect serve_via(:x_accel_redirect) end |
#x_send_file ⇒ Object
serves the file via a header
48 49 50 |
# File 'lib/social_avatar_proxy/configuration.rb', line 48 def x_send_file serve_via(:x_send_file) end |