Class: Site
Class Method Summary collapse
- .bust_cache! ⇒ Object
- .find_by_host!(host) ⇒ Object
-
.find_users_and_superusers(id) ⇒ Object
FIXME clemens thinks this doesn’t belong here.
Instance Method Summary collapse
- #email_from ⇒ Object
- #multi_sites_enabled? ⇒ Boolean
- #owner ⇒ Object
- #owners ⇒ Object
-
#perma_host ⇒ Object
def tag_counts Content.tag_counts :conditions => “site_id = #id” end.
- #plugins ⇒ Object
- #section_ids ⇒ Object
- #users_and_superusers ⇒ Object
Class Method Details
.bust_cache! ⇒ Object
44 45 46 |
# File 'app/models/site.rb', line 44 def bust_cache! all.each(&:touch) end |
.find_by_host!(host) ⇒ Object
31 32 33 34 |
# File 'app/models/site.rb', line 31 def find_by_host!(host) return Site.first if count == 1 && !multi_sites_enabled find_by_host(host) # || raise(ActiveRecord::RecordNotFound, "Could not find site for hostname #{host}.") end |
.find_users_and_superusers(id) ⇒ Object
FIXME clemens thinks this doesn’t belong here. he’s probably right. TODO how to make this an association or assoc extension so we can use it in admin/users_controller?
39 40 41 42 |
# File 'app/models/site.rb', line 39 def find_users_and_superusers(id) User.where(["memberships.site_id = ? OR (memberships.site_id IS NULL AND roles.name = ?)", id, 'superuser']) .includes([:roles, :memberships]).references(:roles, :memberships) end |
Instance Method Details
#email_from ⇒ Object
87 88 89 |
# File 'app/models/site.rb', line 87 def email_from "#{name} <#{email}>" unless name.blank? || email.blank? end |
#multi_sites_enabled? ⇒ Boolean
49 50 51 |
# File 'app/models/site.rb', line 49 def multi_sites_enabled? self.class.multi_sites_enabled end |
#owner ⇒ Object
57 58 59 |
# File 'app/models/site.rb', line 57 def owner nil end |
#owners ⇒ Object
53 54 55 |
# File 'app/models/site.rb', line 53 def owners [] end |
#perma_host ⇒ Object
74 75 76 |
# File 'app/models/site.rb', line 74 def perma_host host.sub(':', '.') # Needed to create valid directories in ms-win end |
#plugins ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'app/models/site.rb', line 78 def plugins @plugins ||= Rails.plugins.values.inject(ActiveSupport::OrderedHash.new) do |plugins, plugin| plugin = plugin.clone plugin.owner = self plugins[plugin.name.to_sym] = plugin plugins end end |
#section_ids ⇒ Object
65 66 67 68 |
# File 'app/models/site.rb', line 65 def section_ids types = Section.types.map { |type| "'#{type}'" }.join(', ') self.class.connection.select_values("SELECT id FROM contents WHERE type IN (#{types}) AND site_id = #{id}") end |
#users_and_superusers ⇒ Object
61 62 63 |
# File 'app/models/site.rb', line 61 def users_and_superusers self.class.find_users_and_superusers(id) end |