Module: Katalyst::Content::Container
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/katalyst/content/container.rb
Instance Method Summary collapse
-
#items_attributes ⇒ Object
Required for testing items validation.
-
#items_attributes=(attributes) ⇒ Object
Updates the current draft version with new structure.
-
#publish! ⇒ Object
Promotes the draft version to become the published version.
- #published? ⇒ Boolean
-
#revert! ⇒ Object
Reverts the draft version to the current published version.
-
#state ⇒ Object
A resource is in draft mode if it has an unpublished draft or it has no published version.
-
#unpublish! ⇒ Object
Sets the currently published version to nil.
Instance Method Details
#items_attributes ⇒ Object
Required for testing items validation
99 100 101 |
# File 'app/models/concerns/katalyst/content/container.rb', line 99 def items_attributes draft_version&.nodes&.as_json end |
#items_attributes=(attributes) ⇒ Object
Updates the current draft version with new structure. Attributes should be structural information about the items, e.g. ‘=> {id:, depth:` or `[depth:]`.
This method conforms to the behaviour of ‘accepts_nested_attributes_for` so that it can be used with rails form helpers.
108 109 110 |
# File 'app/models/concerns/katalyst/content/container.rb', line 108 def items_attributes=(attributes) next_version.nodes = attributes end |
#publish! ⇒ Object
Promotes the draft version to become the published version
81 82 83 84 |
# File 'app/models/concerns/katalyst/content/container.rb', line 81 def publish! update!(published_version: draft_version) self end |
#published? ⇒ Boolean
76 77 78 |
# File 'app/models/concerns/katalyst/content/container.rb', line 76 def published? published_version_id.present? end |
#revert! ⇒ Object
Reverts the draft version to the current published version
87 88 89 90 |
# File 'app/models/concerns/katalyst/content/container.rb', line 87 def revert! update!(draft_version: published_version) self end |
#state ⇒ Object
A resource is in draft mode if it has an unpublished draft or it has no published version.
66 67 68 69 70 71 72 73 74 |
# File 'app/models/concerns/katalyst/content/container.rb', line 66 def state if !published_version_id :unpublished elsif published_version_id != draft_version_id :draft else :published end end |
#unpublish! ⇒ Object
Sets the currently published version to nil
93 94 95 96 |
# File 'app/models/concerns/katalyst/content/container.rb', line 93 def unpublish! update!(published_version_id: nil) self end |