Class: Site
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Site
- Defined in:
- app/models/site.rb
Class Attribute Summary collapse
-
.several ⇒ Object
Returns the value of attribute several.
Class Method Summary collapse
-
.catchall ⇒ Object
If none is found, we are probably brand new, so a workable default site is created.
-
.default ⇒ Object
Site.default returns the the first site it can find with an empty domain pattern.
-
.find_for_host(hostname = '') ⇒ Object
I’ve added one or two sql queries here for the sake of a separate default method.
-
.several? ⇒ Boolean
Returns true if more than one site is present.
Instance Method Summary collapse
- #create_homepage ⇒ Object
-
#dev_url(path = '/') ⇒ Object
Returns the fully specified web address for the development version of this site and the supplied path, or the root of this site if no path is given.
- #reload_routes ⇒ Object
-
#url(path = '/') ⇒ Object
Returns the fully specified web address for the supplied path, or the root of this site if no path is given.
Class Attribute Details
.several ⇒ Object
Returns the value of attribute several.
14 15 16 |
# File 'app/models/site.rb', line 14 def several @several end |
Class Method Details
.catchall ⇒ Object
If none is found, we are probably brand new, so a workable default site is created.
34 35 36 37 38 39 40 41 |
# File 'app/models/site.rb', line 34 def catchall create({ domain: '', name: 'default_site', base_domain: 'localhost', homepage: Page.find_by_parent_id(nil), }) end |
.default ⇒ Object
Site.default returns the the first site it can find with an empty domain pattern.
28 29 30 |
# File 'app/models/site.rb', line 28 def default find_by_domain('') || find_by_domain(nil) || catchall end |
.find_for_host(hostname = '') ⇒ Object
I’ve added one or two sql queries here for the sake of a separate default method
18 19 20 21 22 23 24 |
# File 'app/models/site.rb', line 18 def find_for_host(hostname = '') return default if hostname.blank? sites = includes(:homepage).where('domain IS NOT NULL') site = sites.find { |site| hostname == site.base_domain || hostname =~ Regexp.compile(site.domain) } site || default end |
.several? ⇒ Boolean
Returns true if more than one site is present. This is normally only used to make interface decisions, eg whether to show the site-chooser dropdown.
45 46 47 |
# File 'app/models/site.rb', line 45 def several? several = (count > 1) if several.nil? end |
Instance Method Details
#create_homepage ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/models/site.rb', line 71 def create_homepage if homepage_id.blank? self.homepage = build_homepage(title: "#{name} Homepage", slug: name.to_slug.to_s, breadcrumb: 'Home') default_status = TrustyCms::Config['defaults.page.status'] homepage.status = Status[default_status] if default_status default_parts = TrustyCms::Config['defaults.page.parts'].to_s.strip.split(/\s*,\s*/) default_parts.each do |name| homepage.parts << PagePart.new(name: name, filter_id: TrustyCms::Config['defaults.page.filter']) end save end end |
#dev_url(path = '/') ⇒ Object
Returns the fully specified web address for the development version of this site and the supplied path, or the root of this site if no path is given.
66 67 68 69 |
# File 'app/models/site.rb', line 66 def dev_url(path = '/') uri = URI.join("http://#{TrustyCms::Config['dev.host'] || 'dev'}.#{base_domain}", path) uri.to_s end |
#reload_routes ⇒ Object
85 86 87 |
# File 'app/models/site.rb', line 85 def reload_routes TrustyCms::Application.reload_routes! end |
#url(path = '/') ⇒ Object
Returns the fully specified web address for the supplied path, or the root of this site if no path is given.
59 60 61 62 |
# File 'app/models/site.rb', line 59 def url(path = '/') uri = URI.join("http://#{base_domain}", path) uri.to_s end |