class Lively::Assets
Constants
- DEFAULT_CACHE_CONTROL
- DEFAULT_CONTENT_TYPES
Public Class Methods
new(delegate, root: Dir.pwd, content_types: DEFAULT_CONTENT_TYPES, cache_control: DEFAULT_CACHE_CONTROL)
click to toggle source
Calls superclass method
# File lib/lively/assets.rb, line 36 def initialize(delegate, root: Dir.pwd, content_types: DEFAULT_CONTENT_TYPES, cache_control: DEFAULT_CACHE_CONTROL) super(delegate) @root = root @content_types = content_types @cache_control = cache_control end
Public Instance Methods
call(request)
click to toggle source
Calls superclass method
# File lib/lively/assets.rb, line 70 def call(request) if path = expand_path(request.path) extension = File.extname(path) content_type = @content_types[extension] if path.start_with?(@root) && File.exist?(path) && content_type return response_for(path, content_type) end end super end
expand_path(path)
click to toggle source
# File lib/lively/assets.rb, line 64 def expand_path(path) File.realpath(File.join(@root, path)) rescue Errno::ENOENT nil end
freeze()
click to toggle source
Calls superclass method
# File lib/lively/assets.rb, line 45 def freeze return self if frozen? @root.freeze @content_types.freeze @cache_control.freeze super end
response_for(path, content_type)
click to toggle source
# File lib/lively/assets.rb, line 55 def response_for(path, content_type) headers = [ ['content-type', content_type], ['cache-control', @cache_control], ] return Protocol::HTTP::Response[200, headers, Protocol::HTTP::Body::File.open(path)] end