Class: Alchemy::Site

Inherits:
BaseRecord
  • Object
show all
Includes:
Layout
Defined in:
app/models/alchemy/site.rb

Defined Under Namespace

Modules: Layout

Constant Summary

Constants included from Layout

Layout::SITE_DEFINITIONS_FILE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Layout

#definition, #partial_name

Class Method Details

.currentObject


64
65
66
# File 'app/models/alchemy/site.rb', line 64

def current
  RequestStore.store[:alchemy_current_site] || default
end

.current=(site) ⇒ Object


60
61
62
# File 'app/models/alchemy/site.rb', line 60

def current=(site)
  RequestStore.store[:alchemy_current_site] = site
end

.defaultObject


68
69
70
# File 'app/models/alchemy/site.rb', line 68

def default
  Site.first
end

.find_for_host(host) ⇒ Object


72
73
74
75
76
77
# File 'app/models/alchemy/site.rb', line 72

def find_for_host(host)
  # These are split up into two separate queries in order to run the
  # fastest query first (selecting the domain by its primary host name).
  #
  find_by(host: host) || find_in_aliases(host) || default
end

.find_in_aliases(host) ⇒ Object


79
80
81
82
83
84
85
# File 'app/models/alchemy/site.rb', line 79

def find_in_aliases(host)
  return nil if host.blank?

  all.find do |site|
    site.aliases.split.include?(host) if site.aliases.present?
  end
end

Instance Method Details

#current?Boolean

Returns true if this site is the current site

Returns:

  • (Boolean)

37
38
39
# File 'app/models/alchemy/site.rb', line 37

def current?
  self.class.current == self
end

#default_languageObject

The default language for this site

There can only be one default language per site.


55
56
57
# File 'app/models/alchemy/site.rb', line 55

def default_language
  languages.find_by(default: true)
end

#to_partial_pathObject

Returns the path to site's view partial.

Site view partials live in app/views/alchemy/site_layouts

Please use rails g alchemy:site_layouts to generate partials for all your sites.


47
48
49
# File 'app/models/alchemy/site.rb', line 47

def to_partial_path
  "alchemy/site_layouts/#{partial_name}"
end