Sha256: 3a7ef8dc770c6c75a4db2bf2d626e6978afd6fdfd23fbd1dc85af0475a61fc56

Contents?: true

Size: 782 Bytes

Versions: 1

Compression:

Stored size: 782 Bytes

Contents

# frozen_string_literal: true

module Archangel
  ##
  # Design model
  #
  class Design < ApplicationRecord
    acts_as_paranoid

    validates :content, presence: true
    validates :name, presence: true
    validates :partial, inclusion: { in: [true, false] }

    validate :valid_liquid_content

    belongs_to :parent, -> { where(partial: false) },
               class_name: "Archangel::Design",
               inverse_of: false,
               optional: true
    belongs_to :site

    protected

    def valid_liquid_content
      return if valid_liquid_content?

      errors.add(:content, Archangel.t(:liquid_invalid))
    end

    def valid_liquid_content?
      ::Liquid::Template.parse(content)

      true
    rescue ::Liquid::SyntaxError
      false
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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