Class: Alchemy::Site

Inherits:
ActiveRecord::Base
  • 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_LAYOUTS_FILE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Layout

#layout_definition, #layout_partial_name

Class Method Details

.currentObject



49
50
51
# File 'app/models/alchemy/site.rb', line 49

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

.current=(v) ⇒ Object



45
46
47
# File 'app/models/alchemy/site.rb', line 45

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

.defaultObject



53
54
55
# File 'app/models/alchemy/site.rb', line 53

def default
  Site.first
end

.find_for_host(host) ⇒ Object



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

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).
  #
  where(host: host).first || find_in_aliases(host) || default
end

.find_in_aliases(host) ⇒ Object



64
65
66
67
68
69
70
# File 'app/models/alchemy/site.rb', line 64

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)


30
31
32
# File 'app/models/alchemy/site.rb', line 30

def current?
  self.class.current == self
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.



40
41
42
# File 'app/models/alchemy/site.rb', line 40

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