Class: Replicant::Site
- Inherits:
-
Object
- Object
- Replicant::Site
- Defined in:
- lib/replicant/site.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize ⇒ Site
constructor
A new instance of Site.
- #print_responses ⇒ Object
- #requested?(name, times = 1) ⇒ Boolean
- #requested_via_post?(name, post_data = { }, times = 1) ⇒ Boolean
- #response(name, path, content = "<html><body></body></html") ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize ⇒ Site
Returns a new instance of Site.
3 4 5 |
# File 'lib/replicant/site.rb', line 3 def initialize @responses = [ ] end |
Instance Method Details
#call(env) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/replicant/site.rb', line 28 def call( env ) request = Rack::Request.new( env ) status_code, content = if response = find_response_by_path( request.env[ 'REQUEST_URI' ] ) [ 200, response.content( request.POST ) ] else [ 404, "Not Found" ] end [ status_code, { 'Content-Type' => 'text/html' }, [ content ] ] end |
#print_responses ⇒ Object
41 42 43 |
# File 'lib/replicant/site.rb', line 41 def print_responses @responses.each { |r| puts r } end |
#requested?(name, times = 1) ⇒ Boolean
20 21 22 |
# File 'lib/replicant/site.rb', line 20 def requested?( name, times = 1 ) find_response_by_name( name ).requested?( times ) end |
#requested_via_post?(name, post_data = { }, times = 1) ⇒ Boolean
24 25 26 |
# File 'lib/replicant/site.rb', line 24 def requested_via_post?( name, post_data = { }, times = 1 ) find_response_by_name( name ).requested_via_post?( post_data, times ) end |
#response(name, path, content = "<html><body></body></html") ⇒ Object
15 16 17 18 |
# File 'lib/replicant/site.rb', line 15 def response( name, path, content = "<html><body></body></html" ) remove_response_by_name( name ) if find_response_by_name( name ) @responses << Replicant::Response.new( name, :get, path, content ) end |