Class: Exo::Router

Inherits:
Object
  • Object
show all
Defined in:
app/services/exo/router.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#paramsObject

Returns the value of attribute params.



3
4
5
# File 'app/services/exo/router.rb', line 3

def params
  @params
end

#requestObject

Returns the value of attribute request.



3
4
5
# File 'app/services/exo/router.rb', line 3

def request
  @request
end

#routeObject

Returns the value of attribute route.



3
4
5
# File 'app/services/exo/router.rb', line 3

def route
  @route
end

#siteObject

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

Returns:

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