Class: SiteFramework::Routing::SiteConstraint
- Inherits:
-
Object
- Object
- SiteFramework::Routing::SiteConstraint
- Defined in:
- lib/site_framework/routing/site_constraint.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #domain(name) ⇒ Object
-
#initialize(mapper) ⇒ SiteConstraint
constructor
A new instance of SiteConstraint.
- #matches?(request) ⇒ Boolean
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
#logger ⇒ Object (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 |
# File 'lib/site_framework/routing/site_constraint.rb', line 10 def domain(name) @domain ||= if defined? ActiveRecord SiteFramework::Domain.find_by(name: name) elsif defined? Mongoid SiteFramework::Site.where('domains.name' => name).domains.first else nil end end |
#matches?(request) ⇒ Boolean
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/site_framework/routing/site_constraint.rb', line 20 def matches?(request) @domain_name = request.host if domain_obj = domain(request.host) logger.debug("''#{@domain_name}' matched.") setup(domain_obj) initialize_site_default_state true else logger.info("Domain name '#{request.host}' does not match with any exist domains") false end end |