Class: Skypager::Router
- Inherits:
-
Object
- Object
- Skypager::Router
- Defined in:
- lib/skypager/router.rb
Class Attribute Summary collapse
-
.proxies ⇒ Object
Returns the value of attribute proxies.
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
Class Method Summary collapse
Instance Method Summary collapse
- #authenticator ⇒ Object
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Router
constructor
A new instance of Router.
- #inspect ⇒ Object
- #proxies ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(app, options = {}) ⇒ Router
Returns a new instance of Router.
8 9 10 11 |
# File 'lib/skypager/router.rb', line 8 def initialize(app, ={}) @app = app @options = end |
Class Attribute Details
.proxies ⇒ Object
Returns the value of attribute proxies.
14 15 16 |
# File 'lib/skypager/router.rb', line 14 def proxies @proxies end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
6 7 8 |
# File 'lib/skypager/router.rb', line 6 def app @app end |
Class Method Details
.add(subdomain, options = {}) ⇒ Object
25 26 27 28 29 |
# File 'lib/skypager/router.rb', line 25 def self.add(subdomain, ={}) subdomain = subdomain.to_s self.proxies ||= {} self.proxies[subdomain] = Skypager.proxy() end |
.authenticator(&block) ⇒ Object
35 36 37 38 |
# File 'lib/skypager/router.rb', line 35 def self.authenticator &block @authenticator = block if block_given? @authenticator end |
Instance Method Details
#authenticator ⇒ Object
40 41 42 |
# File 'lib/skypager/router.rb', line 40 def authenticator self.class.authenticator end |
#call(env) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/skypager/router.rb', line 44 def call(env) request = Rack::Request.new(env) subdomain = request.host.split('.').first handler = proxies.fetch(subdomain) do |key| app end if authenticator.respond_to?(:call) if !!authenticator.call(env, subdomain) return [401, {}, [""]] end end handler.call(env) end |
#inspect ⇒ Object
21 22 23 |
# File 'lib/skypager/router.rb', line 21 def inspect to_s end |
#proxies ⇒ Object
31 32 33 |
# File 'lib/skypager/router.rb', line 31 def proxies self.class.proxies end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/skypager/router.rb', line 17 def to_s "Skypager Router. Serving #{ proxies.keys.join(", ") }" end |