Class: Alchemy::Page::FixedAttributes

Inherits:
Object
  • Object
show all
Defined in:
app/models/alchemy/page/fixed_attributes.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page) ⇒ FixedAttributes

Returns a new instance of FixedAttributes.


22
23
24
# File 'app/models/alchemy/page/fixed_attributes.rb', line 22

def initialize(page)
  @page = page
end

Instance Attribute Details

#pageObject (readonly)

Returns the value of attribute page


20
21
22
# File 'app/models/alchemy/page/fixed_attributes.rb', line 20

def page
  @page
end

Instance Method Details

#[](name) ⇒ Object

Returns the attribute by key


60
61
62
63
64
# File 'app/models/alchemy/page/fixed_attributes.rb', line 60

def [](name)
  return nil if name.nil?

  attributes[name.to_sym]
end

#any?Boolean Also known as: present?

True if fixed attributes are defined on page

Aliased as #present?

Returns:

  • (Boolean)

    Boolean


43
44
45
# File 'app/models/alchemy/page/fixed_attributes.rb', line 43

def any?
  attributes.present?
end

#attributesObject Also known as: all

All fixed attributes defined on page

Aliased as #all

Returns:

  • Hash


32
33
34
# File 'app/models/alchemy/page/fixed_attributes.rb', line 32

def attributes
  @_attributes ||= page.definition.fetch("fixed_attributes", {}).symbolize_keys
end

#fixed?(name) ⇒ Boolean

True if given attribute name is defined on page

Returns:

  • (Boolean)

    Boolean


52
53
54
55
56
# File 'app/models/alchemy/page/fixed_attributes.rb', line 52

def fixed?(name)
  return false if name.nil?

  attributes.key?(name.to_sym)
end