Sha256: 8c7028f8eb9578f8b00c4d7794855ca83951a529101fb56c5391fb42d5f7b07a

Contents?: true

Size: 773 Bytes

Versions: 35

Compression:

Stored size: 773 Bytes

Contents

class Site < ActiveRecord::Base
  
  validates_uniqueness_of :domain
  
  before_validation :remove_www
  
  before_save :unset_default
  after_save :set_default
  
  named_scope :default, :conditions => {:the_default => true}
    
  def self.find_by_domain(domain)
    d = domain.clone
    strip_www!(d)
    if site = first(:conditions => {:domain => d})
      site
    else
      default.first
    end
  end
  
  def self.strip_www!(d)
    return unless d
    d.sub!(/\Awww./,'')
  end  
    
  def remove_www
    self.class.strip_www!(domain)
  end

  def unset_default    
    self.class.update_all(["the_default = ?", false]) if the_default
  end
  
  def set_default
    if self.class.default.count < 1
      update_attribute(:the_default, true)
    end
  end
  
end

Version data entries

35 entries across 35 versions & 11 rubygems

Version Path
SFEley-browsercms-3.0.2 app/models/site.rb
buzzware-browsercms-3.0.2 app/models/site.rb
coredumplings-browsercms-3.0.0 app/models/site.rb
nate-browsercms-3.0.210 app/models/site.rb
nate-browsercms-3.0.211 app/models/site.rb
we5-browsercms-3.0.1.1 app/models/site.rb
webficient-browsercms-3.0.1 app/models/site.rb
webficient-browsercms-3.0.2 app/models/site.rb
webficient-browsercms-3.0.3 app/models/site.rb
webficient-browsercms-3.0.4 app/models/site.rb
browsercms-3.1.5 app/models/site.rb
browsercms-3.1.4 app/models/site.rb
browsercms-3.1.3 app/models/site.rb
bf4-browsercms-3.1.0 app/models/site.rb
drujensen-browsercms-3.2.0 app/models/site.rb
browsercmsi-3.1.2 app/models/site.rb
browsercms-3.1.2 app/models/site.rb
browsercms-3.1.1 app/models/site.rb
browsercmsi-3.1.1 app/models/site.rb
browsercmsi-3.1.0 app/models/site.rb