Module: HttpStub::Server::Application::Routes::Stub

Included in:
Application
Defined in:
lib/http_stub/server/application/routes/stub.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(application) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/http_stub/server/application/routes/stub.rb', line 14

def self.included(application)
  application.instance_eval do

    namespace "/http_stub/stubs" do

      get do
        haml :stubs, {}, stubs: @stub_controller.find_all(http_stub_request)
      end

      post "/reset" do
        @stub_controller.reset(http_stub_request, logger)
        halt 200, "OK"
      end

      namespace "/matches" do

        get do
          haml :stub_matches, {}, matches: @stub_match_controller.matches(http_stub_request)
        end

        get "/last" do
          response = @stub_match_controller.last_match(http_stub_request, logger)
          response.serve_on(self)
        end

      end

      get "/misses" do
        haml :stub_misses, {}, misses: @stub_match_controller.misses(http_stub_request)
      end

      get "/:stub_id" do
        establish_http_stub_request
        haml :stub, {}, the_stub: @stub_controller.find(http_stub_request, logger)
      end

    end

    any_request_method "*" do
      response = @stub_controller.match(http_stub_request, logger)
      response.serve_on(self)
    end

  end
end

Instance Method Details

#initializeObject


8
9
10
11
12
# File 'lib/http_stub/server/application/routes/stub.rb', line 8

def initialize
  super()
  @stub_controller       = HttpStub::Server::Stub::Controller.new
  @stub_match_controller = HttpStub::Server::Stub::Match::Controller.new
end