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.



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

def initialize(page)
  @page = page
end

Instance Attribute Details

#pageObject (readonly)

Returns the value of attribute page.



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

def page
  @page
end

Instance Method Details

#[](name) ⇒ Object

Returns the attribute by key



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

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



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

def any?
  attributes.present?
end

#attributesObject Also known as: all

All fixed attributes defined on page

Aliased as #all

Returns:

  • Hash



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

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



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

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

  attributes.key?(name.to_sym)
end