Sha256: cb72b785728fe2030fcd66bdc3e3a619617da5ce862cb456ff3445c8e1d8f009
Contents?: true
Size: 740 Bytes
Versions: 7
Compression:
Stored size: 740 Bytes
Contents
module Spree class Store < Spree::Base validates :code, presence: true, uniqueness: true validates :name, presence: true validates :url, presence: true validates :mail_from_address, presence: true before_create :ensure_default_exists_and_is_unique scope :by_url, lambda { |url| where("url like ?", "%#{url}%") } def self.current(domain = nil) current_store = domain ? Store.by_url(domain).first : nil current_store || Store.default end def self.default where(default: true).first || new end private def ensure_default_exists_and_is_unique if default Store.update_all(default: false) else self.default = true end end end end
Version data entries
7 entries across 7 versions & 1 rubygems