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

.find_by_hostname(hostname) ⇒ Object



37
38
39
40
41
42
43
# File 'app/models/site.rb', line 37

def self.find_by_hostname(hostname)
  # allow vhost to be added to existing sites
  if Site.count == 0
    Site.create!(:hostname => hostname)
  end
  self.find(:first, :conditions => ["hostname LIKE ?", "%#{hostname}%"])
end

Instance Method Details

#allow_access_for(user) ⇒ Object



28
29
30
31
# File 'app/models/site.rb', line 28

def allow_access_for(user)
  # Site Admins can access all sites. Users can only access sites to which they belong
  user.site_admin? || self.users.include?(user)
end

#homepageObject



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

def homepage
  self.pages.find(:first, :conditions => {:parent_id => nil})
end

#hostname=(val) ⇒ Object



18
19
20
# File 'app/models/site.rb', line 18

def hostname=(val)
  hostnames.first.update_attributes(:domain => val)
end

#titleObject



13
14
15
16
# File 'app/models/site.rb', line 13

def title
  self.config ||= {}
  self.config['title']
end

#title=(val) ⇒ Object



8
9
10
11
# File 'app/models/site.rb', line 8

def title=(val)
  self.config ||= {}
  self.config['title'] = val
end