Module: ShamRack::Registry

Included in:
ShamRack
Defined in:
lib/sham_rack/registry.rb

Instance Method Summary collapse

Instance Method Details

#application_for(address, port = nil) ⇒ Object



30
31
32
33
# File 'lib/sham_rack/registry.rb', line 30

def application_for(address, port = nil)
  port ||= Net::HTTP.default_port
  registry[[address, port]]
end

#lambda(address, port = nil, &block) ⇒ Object



15
16
17
# File 'lib/sham_rack/registry.rb', line 15

def lambda(address, port = nil, &block)
  mount(block, address, port)
end

#mount(rack_app, address, port = nil) ⇒ Object



5
6
7
8
# File 'lib/sham_rack/registry.rb', line 5

def mount(rack_app, address, port = nil)
  port ||= Net::HTTP.default_port
  registry[[address, port]] = rack_app
end

#rackup(address, port = nil, &block) ⇒ Object



10
11
12
13
# File 'lib/sham_rack/registry.rb', line 10

def rackup(address, port = nil, &block)
  app = Rack::Builder.new(&block).to_app
  mount(app, address, port)
end

#sinatra(address, port = nil, &block) ⇒ Object



19
20
21
22
23
24
# File 'lib/sham_rack/registry.rb', line 19

def sinatra(address, port = nil, &block)
  require "sinatra/base"
  sinatra_app = Class.new(Sinatra::Base)
  sinatra_app.class_eval(&block)
  mount(sinatra_app.new, address, port)
end

#unmount_allObject



26
27
28
# File 'lib/sham_rack/registry.rb', line 26

def unmount_all
  registry.clear
end