Class: Rack::ActsAsCaesar
- Inherits:
-
Object
- Object
- Rack::ActsAsCaesar
- Defined in:
- lib/acts_as_caesar/rack.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app = nil) ⇒ ActsAsCaesar
constructor
A new instance of ActsAsCaesar.
Constructor Details
#initialize(app = nil) ⇒ ActsAsCaesar
Returns a new instance of ActsAsCaesar.
10 11 12 |
# File 'lib/acts_as_caesar/rack.rb', line 10 def initialize(app = nil) @app = app end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
8 9 10 |
# File 'lib/acts_as_caesar/rack.rb', line 8 def app @app end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
8 9 10 |
# File 'lib/acts_as_caesar/rack.rb', line 8 def request @request end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/acts_as_caesar/rack.rb', line 14 def call(env) # pass through app if response already exists if app status, headers, body = app.call(env) return [status, headers, body] unless status == 404 end @request = Rack::Request.new(env) if request.path =~ /\/votes\/(\w+)\/([\w\-]+).json/ if request.get? render_votes($1, $2) elsif request.post? update_vote($1, $2, request.params['value'].to_i) else method_not_allowed end else not_found end end |