Class: SiteFramework::Routing::SiteConstraint

Inherits:
Object
  • Object
show all
Defined in:
lib/site_framework/routing/site_constraint.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mapper) ⇒ SiteConstraint

Returns a new instance of SiteConstraint.



5
6
7
8
# File 'lib/site_framework/routing/site_constraint.rb', line 5

def initialize(mapper)
  @logger = Rails.logger
  @mapper = mapper
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



3
4
5
# File 'lib/site_framework/routing/site_constraint.rb', line 3

def logger
  @logger
end

Instance Method Details

#domain(name) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/site_framework/routing/site_constraint.rb', line 10

def domain(name)
  return @domain if @domain_name == name

  if defined? ActiveRecord
    @domain = SiteFramework::Domain.find_by(name: name)
  elsif defined? Mongoid
    @domain = SiteFramework::Site.where('domains.name' => name).domains.first
  else
    nil
  end
end

#matches?(request) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/site_framework/routing/site_constraint.rb', line 22

def matches?(request)
  if domain_obj = domain(request.host)
    @domain_name = request.host
    logger.debug("'#{@domain_name}' matched.")
    setup(domain_obj, request)
    initialize_site_default_state

    true
  else
    logger.info("Domain name '#{request.host}' does not match with any exist domains")
    set_request_data_to_nil(request)
    @domain_name = request.host
    false
  end
end