Class: Site

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.bust_cache!Object



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

def bust_cache!
  all.each(&:touch)
end

.find_by_host!(host) ⇒ Object



32
33
34
35
# File 'app/models/site.rb', line 32

def find_by_host!(host)
  return Site.first if count == 1 && !multi_sites_enabled
  where("? = ANY (hosts)", host).first or raise ActiveRecord::RecordNotFound
end

Instance Method Details

#email_fromObject



80
81
82
# File 'app/models/site.rb', line 80

def email_from
  "#{name} <#{email}>" unless name.blank? || email.blank?
end

#grouped_activitiesObject



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

def grouped_activities
  activities.find_coinciding_grouped_by_dates(Time.zone.now.to_date, 1.day.ago.to_date)
end

#multi_sites_enabled?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/models/site.rb', line 42

def multi_sites_enabled?
  self.class.multi_sites_enabled
end

#ownerObject



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

def owner
  nil
end

#ownersObject



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

def owners
  []
end

#perma_hostObject

def tag_counts

Content.tag_counts :conditions => "site_id = #{id}"

end



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

def perma_host
  host.sub(':', '.')  # Needed to create valid directories in ms-win
end

#pluginsObject



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

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_idsObject



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

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