Class: StatusCats
- Inherits:
-
Object
- Object
- StatusCats
- Defined in:
- lib/status_cats.rb
Constant Summary collapse
- CATS =
[ 100, 200, 206, 207, 300, 301, 302, 303, 307, 401, 402, 403, 404, 405, 406, 408, 409, 410, 413, 414, 416, 417, 418, 422, 423, 424, 426, 429, 431, 444, 450, 500, 502, 507, 508, 599 ].freeze
- CATS_DIR =
File.("../../cats", __FILE__)
Instance Method Summary collapse
- #call(env) ⇒ Object
- #display_cat? ⇒ Boolean
-
#initialize(app, options = {}) ⇒ StatusCats
constructor
A new instance of StatusCats.
Constructor Details
#initialize(app, options = {}) ⇒ StatusCats
Returns a new instance of StatusCats.
8 9 10 |
# File 'lib/status_cats.rb', line 8 def initialize(app, = {}) @app, @options = app, end |
Instance Method Details
#call(env) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/status_cats.rb', line 12 def call(env) @status, @headers, @response = @app.call(env) if display_cat? _, @headers, @response = Rack::File.new(CATS_DIR).call("PATH_INFO" => "#{@status}.jpg") end [ @status, @headers, @response ] end |
#display_cat? ⇒ Boolean
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/status_cats.rb', line 20 def display_cat? cats = CATS if @options.has_key?(:only) cats = Array(@options[:only]) & cats end if @options.has_key?(:except) cats = cats - Array(@options[:except]) end cats.include?(@status.to_i) end |