Sha256: 131fd38c9eb322489efcc8d83a9b9a5073d78c94458a3593dfed62bea63cc986

Contents?: true

Size: 1.29 KB

Versions: 39

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module Alchemy
  # = Fixed page attributes
  #
  # Fixed page attributes are not allowed to be changed by the user.
  #
  # Define fixed page attributes on the page layout definition of a page.
  #
  # == Example
  #
  #     # page_layout.yml
  #     - name: Index
  #       unique: true
  #       fixed_attributes:
  #         - public_on: nil
  #         - public_until: nil
  #         - visible: false
  #
  class Page::FixedAttributes
    attr_reader :page

    def initialize(page)
      @page = page
    end

    # All fixed attributes defined on page
    #
    # Aliased as +#all+
    #
    # @return Hash
    #
    def attributes
      @_attributes ||= page.definition.fetch('fixed_attributes', {}).symbolize_keys
    end
    alias_method :all, :attributes

    # True if fixed attributes are defined on page
    #
    # Aliased as +#present?+
    #
    # @return Boolean
    #
    def any?
      attributes.present?
    end
    alias_method :present?, :any?

    # True if given attribute name is defined on page
    #
    # @return Boolean
    #
    def fixed?(name)
      return false if name.nil?
      attributes.key?(name.to_sym)
    end

    # Returns the attribute by key
    #
    def [](name)
      return nil if name.nil?
      attributes[name.to_sym]
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
alchemy_cms-4.6.7 app/models/alchemy/page/fixed_attributes.rb
alchemy_cms-4.6.6 app/models/alchemy/page/fixed_attributes.rb
alchemy_cms-4.6.5 app/models/alchemy/page/fixed_attributes.rb
alchemy_cms-4.5.1 app/models/alchemy/page/fixed_attributes.rb
alchemy_cms-4.4.5 app/models/alchemy/page/fixed_attributes.rb
alchemy_cms-4.6.4 app/models/alchemy/page/fixed_attributes.rb
alchemy_cms-4.0.6 app/models/alchemy/page/fixed_attributes.rb
alchemy_cms-4.6.3 app/models/alchemy/page/fixed_attributes.rb
alchemy_cms-4.6.2 app/models/alchemy/page/fixed_attributes.rb
alchemy_cms-4.6.1 app/models/alchemy/page/fixed_attributes.rb
alchemy_cms-4.6.0 app/models/alchemy/page/fixed_attributes.rb
alchemy_cms-4.5.0 app/models/alchemy/page/fixed_attributes.rb
alchemy_cms-4.4.4 app/models/alchemy/page/fixed_attributes.rb
alchemy_cms-4.4.3 app/models/alchemy/page/fixed_attributes.rb
alchemy_cms-4.4.2 app/models/alchemy/page/fixed_attributes.rb
alchemy_cms-4.4.1 app/models/alchemy/page/fixed_attributes.rb
alchemy_cms-4.4.0 app/models/alchemy/page/fixed_attributes.rb
alchemy_cms-4.3.2 app/models/alchemy/page/fixed_attributes.rb
alchemy_cms-4.2.4 app/models/alchemy/page/fixed_attributes.rb
alchemy_cms-4.3.1 app/models/alchemy/page/fixed_attributes.rb