class Shutterbug::Rackapp
Constants
- DefaultHandlers
Public Class Methods
new(app=nil) { |config| ... }
click to toggle source
# File lib/shutterbug/rackapp.rb, line 22 def initialize(app=nil, &block) @handlers = {} @config = Configuration.instance yield @config if block_given? @app = app add_default_handlers log "initialized" end
Public Instance Methods
add_default_handlers()
click to toggle source
# File lib/shutterbug/rackapp.rb, line 18 def add_default_handlers DefaultHandlers.each { |h| add_handler(h) } end
add_handler(klass)
click to toggle source
# File lib/shutterbug/rackapp.rb, line 12 def add_handler(klass) instance = klass.new log "adding handler for #{klass.regex} ➙ #{klass.name}" @handlers[klass.regex] = instance end
call(env)
click to toggle source
# File lib/shutterbug/rackapp.rb, line 31 def call(env) req = Rack::Request.new(env) result = false @handlers.keys.each do |path_regex| if req.path =~ path_regex result = @handlers[path_regex].handle(self, req, env) end end result || skip(env) end
log(string)
click to toggle source
# File lib/shutterbug/rackapp.rb, line 52 def log(string) puts "★ shutterbug #{Shutterbug::VERSION} ➙ #{string}" end
response(content, type, status=200, cachable=true)
click to toggle source
# File lib/shutterbug/rackapp.rb, line 42 def response(content, type, status=200, cachable=true) headers = {} size = content.respond_to?(:bytesize) ? content.bytesize : content.size headers['Content-Length'] = size.to_s headers['Content-Type'] = type headers['Cache-Control'] = 'no-cache' unless cachable content = [content] unless content.respond_to? 'each' return [status, headers, content] end
skip(env)
click to toggle source
# File lib/shutterbug/rackapp.rb, line 56 def skip(env) # call the applicaiton default @app.call(env) if @app end