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_domain(domain) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'app/models/site.rb', line 12

def self.find_by_domain(domain)
  d = domain.clone
  strip_www!(d)
  if site = first(:conditions => {:domain => d})
    site
  else
    default.first
  end
end

.strip_www!(d) ⇒ Object



22
23
24
25
# File 'app/models/site.rb', line 22

def self.strip_www!(d)
  return unless d
  d.sub!(/\Awww./,'')
end

Instance Method Details

#remove_wwwObject



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

def remove_www
  self.class.strip_www!(domain)
end

#set_defaultObject



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

def set_default
  if self.class.default.count < 1
    update_attribute(:the_default, true)
  end
end

#unset_defaultObject



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

def unset_default    
  self.class.update_all(["the_default = ?", false]) if the_default
end