Class: Replicant::Site

Inherits:
Object
  • Object
show all
Defined in:
lib/replicant/site.rb

Instance Method Summary collapse

Constructor Details

#initializeSite

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


41
42
43
# File 'lib/replicant/site.rb', line 41

def print_responses
  @responses.each { |r| puts r }
end

#requested?(name, times = 1) ⇒ Boolean

Returns:

  • (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

Returns:

  • (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

#startObject



7
8
9
# File 'lib/replicant/site.rb', line 7

def start
  Replicant::Server.start self, 9000
end

#stopObject



11
12
13
# File 'lib/replicant/site.rb', line 11

def stop
  Replicant::Server.stop
end