Class: Alchemy::Page::FixedAttributes
- Inherits:
-
Object
- Object
- Alchemy::Page::FixedAttributes
- 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
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Returns the attribute by key.
-
#any? ⇒ Boolean
(also: #present?)
True if fixed attributes are defined on page.
-
#attributes ⇒ Object
(also: #all)
All fixed attributes defined on page.
-
#fixed?(name) ⇒ Boolean
True if given attribute name is defined on page.
-
#initialize(page) ⇒ FixedAttributes
constructor
A new instance of FixedAttributes.
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
#page ⇒ Object (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?
44 45 46 |
# File 'app/models/alchemy/page/fixed_attributes.rb', line 44 def any? attributes.present? end |
#attributes ⇒ Object Also known as: all
All fixed attributes defined on page
Aliased as #all
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
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 |