Class: Comfy::Cms::Site

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/comfy/cms/site.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_site(host, path = nil) ⇒ Object

– Class Methods ———————————————————– returning the Comfy::Cms::Site instance based on host and path



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/comfy/cms/site.rb', line 33

def self.find_site(host, path = nil)
  return Comfy::Cms::Site.first if Comfy::Cms::Site.count == 1
  cms_site = nil


  public_cms_path = ComfortableMexicanSofa.configuration.public_cms_path
  path.gsub!(/\A#{public_cms_path}/, '') unless path.nil? || public_cms_path == '/'

  Comfy::Cms::Site.where(hostname: real_host_from_aliases(host)).each do |site|
    if site.path.blank?
      cms_site = site
    elsif "#{path.to_s.split('?')[0]}/".match /^\/#{Regexp.escape(site.path.to_s)}\//
      cms_site = site
      break
    end
  end
  return cms_site
end

Instance Method Details

#url(relative: false) ⇒ Object

– Instance Methods ——————————————————–



53
54
55
56
57
58
# File 'app/models/comfy/cms/site.rb', line 53

def url(relative: false)
  public_cms_path = ComfortableMexicanSofa.config.public_cms_path || '/'
  host = "//#{self.hostname}"
  path = ['/', public_cms_path, self.path].compact.join('/').squeeze('/').chomp('/')
  relative ? path.presence : [host, path].join
end