class Dragonfly::Cache::Config
Attributes
servers_options[RW]
Public Class Methods
new(servers_options = {})
click to toggle source
# File lib/dragonfly/cache/config.rb, line 8 def initialize(servers_options = {}) self.servers_options = { url_format: '/dragonfly-cache/:sha/:name', server_root: File.join(Dir.pwd, 'public') }.merge(servers_options) validate! rewrite_url_format! end
Public Instance Methods
base_dir()
click to toggle source
# File lib/dragonfly/cache/config.rb, line 18 def base_dir @base_dir ||= begin path_format = File.join(servers_options[:server_root], servers_options[:url_format]) path_format.split('/').take_while { |p| p != ':shaish' }.join('/') end end
Protected Instance Methods
rewrite_url_format!()
click to toggle source
# File lib/dragonfly/cache/config.rb, line 35 def rewrite_url_format! servers_options[:url_format] = servers_options[:url_format].gsub(%r{/:sha}, '/:shaish') servers_options[:url_format] = servers_options[:url_format].gsub(%r{/:name}, '/:normalized_name') end
validate!()
click to toggle source
# File lib/dragonfly/cache/config.rb, line 27 def validate! if servers_options[:server_root].nil? || !File.exist?(servers_options[:server_root]) raise Dragonfly::Cache::Error, ':server_root option is missing or directory does not exist' end raise Dragonfly::Cache::Error, ':url_format option must include `:sha`' if (servers_options[:url_format] =~ %r{/:sha/}).nil? end