Class: Rack::Quote

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/ricky_quote.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options={})
  @app = app
  @options = options
  @phrases = []
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



3
4
5
# File 'lib/rack/ricky_quote.rb', line 3

def app
  @app
end

#envObject (readonly)

Returns the value of attribute env.



3
4
5
# File 'lib/rack/ricky_quote.rb', line 3

def env
  @env
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/rack/ricky_quote.rb', line 3

def options
  @options
end

Instance Method Details

#afterObject



26
27
# File 'lib/rack/ricky_quote.rb', line 26

def after
end

#beforeObject



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_phraseObject



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

#requestObject



29
30
31
# File 'lib/rack/ricky_quote.rb', line 29

def request
	Rack::Request.new(@env)
end

#responseObject



33
34
35
# File 'lib/rack/ricky_quote.rb', line 33

def response
	Rack::Response.new(@response)
end