Class: Cms::Site

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_domain(domain) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'app/models/cms/site.rb', line 15

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



25
26
27
28
# File 'app/models/cms/site.rb', line 25

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

Instance Method Details

#remove_wwwObject



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

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

#set_defaultObject



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

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

#unset_defaultObject



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

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