Sha256: f68106ad0f0abf6fb9c226c791c3024629e231eecbc23e8eee9e36c3b825879c

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

class Cms::Site < ActiveRecord::Base
  
  if ComfortableMexicanSofa.config.database_config && !Rails.env.test?
    establish_connection "#{ComfortableMexicanSofa.config.database_config}_#{Rails.env}"
  end
  
  set_table_name :cms_sites
  
  # -- Relationships --------------------------------------------------------
  has_many :layouts,  :dependent => :destroy
  has_many :pages,    :dependent => :destroy
  has_many :snippets, :dependent => :destroy
  has_many :files,    :dependent => :destroy
  
  # -- Callbacks ------------------------------------------------------------
  before_validation :assign_label
  before_save :clean_path
  
  # -- Validations ----------------------------------------------------------
  validates :label,
    :presence   => true
  validates :hostname,
    :presence   => true,
    :uniqueness => { :scope => :path },
    :format     => { :with => /^[\w\.\-]+$/ }
    
  # -- Scopes ---------------------------------------------------------------
  scope :mirrored, where(:is_mirrored => true)
  
protected
  
  def assign_label
    self.label = self.label.blank?? self.hostname : self.label
  end
  
  def clean_path
    self.path ||= ''
    self.path.squeeze!('/')
    self.path.gsub!(/\/$/, '')
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-1.4.7 app/models/cms/site.rb
comfortable_mexican_sofa-1.4.6 app/models/cms/site.rb