Sha256: 851d9c3dd55504ec623117d36ab0133965dfa998c3cf992754816aff66753bf7

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

module Archangel
  ##
  # Site model
  #
  class Site < ApplicationRecord
    include Archangel::Models::MetatagableConcern

    acts_as_paranoid

    mount_uploader :logo, Archangel::LogoUploader

    typed_store :settings, coder: JSON do |setting|
      setting.boolean :allow_registration, default: false
      setting.boolean :homepage_redirect, default: false
      setting.datetime :preferred_at, default: Time.current, accessor: false
    end

    validates :locale, presence: true, inclusion: { in: Archangel::LANGUAGES }
    validates :logo, file_size: {
      less_than_or_equal_to: Archangel.config.image_maximum_file_size
    }
    validates :name, presence: true
    validates :theme, inclusion: { in: Archangel.themes }, allow_blank: true

    validates :allow_registration, inclusion: { in: [true, false] }
    validates :homepage_redirect, inclusion: { in: [true, false] }

    has_many :assets, dependent: :destroy
    has_many :collections, dependent: :destroy
    has_many :designs, dependent: :destroy
    has_many :pages, dependent: :destroy
    has_many :users, dependent: :destroy
    has_many :widgets, dependent: :destroy

    has_many :entries, through: :collections
    has_many :fields, through: :collections

    ##
    # Current site
    #
    # @return [Object] first availabe site as current site
    #
    def self.current
      first_or_create do |site|
        site.name = "Archangel"
      end
    end

    ##
    # Liquid object for Site
    #
    # @return [Object] the Liquid object
    #
    def to_liquid
      Archangel::Liquid::Drops::SiteDrop.new(self)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
archangel-0.4.0 app/models/archangel/site.rb