Class: Rack::Quote
- Inherits:
-
Object
- Object
- Rack::Quote
- Defined in:
- lib/rack/ricky_quote.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #after ⇒ Object
- #before ⇒ Object
- #call(env) ⇒ Object
- #call!(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Quote
constructor
A new instance of Quote.
- #random_phrase ⇒ Object
- #request ⇒ Object
- #response ⇒ Object
Constructor Details
#initialize(app, options = {}) ⇒ Quote
Returns a new instance of Quote.
5 6 7 8 9 |
# File 'lib/rack/ricky_quote.rb', line 5 def initialize(app, ={}) @app = app @options = @phrases = [] end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
3 4 5 |
# File 'lib/rack/ricky_quote.rb', line 3 def app @app end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
3 4 5 |
# File 'lib/rack/ricky_quote.rb', line 3 def env @env end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/rack/ricky_quote.rb', line 3 def @options end |
Instance Method Details
#after ⇒ Object
26 27 |
# File 'lib/rack/ricky_quote.rb', line 26 def after end |
#before ⇒ Object
23 24 |
# File 'lib/rack/ricky_quote.rb', line 23 def before end |
#call(env) ⇒ Object
11 12 13 |
# File 'lib/rack/ricky_quote.rb', line 11 def call(env) dup.call!(env) end |
#call!(env) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/rack/ricky_quote.rb', line 15 def call!(env) before @env = env status, headers, @response = @app.call(@env) @response.write "Something" if @env['PATH_INFO'] == '/quote' after || @response end |
#random_phrase ⇒ Object
37 38 39 40 41 42 |
# File 'lib/rack/ricky_quote.rb', line 37 def random_phrase ::File.open("rickygervais.txt").each_line do |line| @phrases << line.chomp end @phrases.shuffle.first end |
#request ⇒ Object
29 30 31 |
# File 'lib/rack/ricky_quote.rb', line 29 def request Rack::Request.new(@env) end |
#response ⇒ Object
33 34 35 |
# File 'lib/rack/ricky_quote.rb', line 33 def response Rack::Response.new(@response) end |