Sha256: cd28def4ebd81a68c21735774046c858ee12f29e826dbad7ed1e28ca50f050ba

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

module Pageflow
  # Override theme options and upload theme files for an entry type on
  # a per account basis.
  #
  # @since 15.7
  class ThemeCustomization < ApplicationRecord
    belongs_to :account

    serialize :overrides, JSON
    serialize :selected_file_ids, JSON

    has_many :uploaded_files, class_name: 'ThemeCustomizationFile'

    # Options that were passed to [ThemeCustomizations#update].
    #
    # @return [Hash<Symbol, Object>]
    def overrides
      super&.deep_symbolize_keys || {}
    end

    # Theme customization files that have been assigned a role via
    # [ThemeCustomizations#update].
    #
    # @return [Hash<Symbol, ThemeCustomizationFile>]
    def selected_files
      selected_file_ids.compact.transform_values do |id|
        selected_files_by_id[id]
      end
    end

    # @api private
    def entry_type
      Pageflow.config.entry_types.find_by_name!(entry_type_name)
    end

    private

    def selected_file_ids
      super&.deep_symbolize_keys || {}
    end

    def selected_files_by_id
      @selected_files_by_id ||= uploaded_files.where(id: selected_file_ids.values).index_by(&:id)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pageflow-15.8.0 app/models/pageflow/theme_customization.rb
pageflow-15.7.1 app/models/pageflow/theme_customization.rb
pageflow-15.7.0 app/models/pageflow/theme_customization.rb