Class: Exo::Router
- Inherits:
-
Object
- Object
- Exo::Router
- Defined in:
- app/services/exo/router.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
-
#request ⇒ Object
Returns the value of attribute request.
-
#route ⇒ Object
Returns the value of attribute route.
-
#site ⇒ Object
Returns the value of attribute site.
Class Method Summary collapse
Instance Method Summary collapse
- #domain_redirection?(host) ⇒ Boolean
- #for_request!(request) ⇒ Object
- #host_url(path = '') ⇒ Object
-
#initialize(site) ⇒ Router
constructor
A new instance of Router.
Constructor Details
#initialize(site) ⇒ Router
Returns a new instance of Router.
11 12 13 |
# File 'app/services/exo/router.rb', line 11 def initialize site self.site = SiteDecorator.new site end |
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
3 4 5 |
# File 'app/services/exo/router.rb', line 3 def params @params end |
#request ⇒ Object
Returns the value of attribute request.
3 4 5 |
# File 'app/services/exo/router.rb', line 3 def request @request end |
#route ⇒ Object
Returns the value of attribute route.
3 4 5 |
# File 'app/services/exo/router.rb', line 3 def route @route end |
#site ⇒ Object
Returns the value of attribute site.
3 4 5 |
# File 'app/services/exo/router.rb', line 3 def site @site end |
Class Method Details
.for_host!(host) ⇒ Object
5 6 7 8 9 |
# File 'app/services/exo/router.rb', line 5 def self.for_host! host site = Site.any_of([{hosts: host}, {main_host: host}]).first raise ::Exo::Site::UnknowHostError.new(host) unless site new site end |
Instance Method Details
#domain_redirection?(host) ⇒ Boolean
15 16 17 |
# File 'app/services/exo/router.rb', line 15 def domain_redirection?(host) site.main_host.to_s != host end |
#for_request!(request) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'app/services/exo/router.rb', line 23 def for_request! request unless self.route Exo::PathMatcher.route_for(site.routes, request.params) do |route| self.route = Exo::RouteDecorator.new route end raise ::Exo::Route::UnknowPathError.new site.main_host, request.path unless route end self.route end |
#host_url(path = '') ⇒ Object
19 20 21 |
# File 'app/services/exo/router.rb', line 19 def host_url path='' "http://#{site.main_host}#{path}" end |