Class: StatusDogs
- Inherits:
-
Object
- Object
- StatusDogs
- Defined in:
- lib/status_dogs.rb
Constant Summary collapse
- DOGS =
[ 100, 200, 201, 202, 203, 206, 207, 208, 226, 300, 301, 302, 303, 305, 306, 307, 308, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 416, 417, 418, 420, 422, 423, 424, 425, 426, 429, 431, 444, 450, 451, 494, 500, 501, 502, 503, 504, 506, 507, 508, 509, 510 ].freeze
- DOGS_DIR =
File.("../../dogs", __FILE__)
Instance Method Summary collapse
- #call(env) ⇒ Object
- #display_dog? ⇒ Boolean
-
#initialize(app, options = {}) ⇒ StatusDogs
constructor
A new instance of StatusDogs.
Constructor Details
#initialize(app, options = {}) ⇒ StatusDogs
Returns a new instance of StatusDogs.
8 9 10 |
# File 'lib/status_dogs.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_dogs.rb', line 12 def call(env) @status, @headers, @response = @app.call(env) if display_dog? _, @headers, @response = Rack::File.new(DOGS_DIR).call("REQUEST_METHOD" => "GET", "PATH_INFO" => "#{@status}.jpg") end [ @status, @headers, @response ] end |
#display_dog? ⇒ Boolean
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/status_dogs.rb', line 20 def display_dog? dogs = DOGS if @options.has_key?(:only) dogs = Array(@options[:only]) & dogs end if @options.has_key?(:except) dogs = dogs - Array(@options[:except]) end dogs.include?(@status.to_i) end |