Module: Katalyst::Content::Container

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/katalyst/content/container.rb

Instance Method Summary collapse

Instance Method Details

#items_attributesObject

Required for testing items validation



130
131
132
# File 'app/models/concerns/katalyst/content/container.rb', line 130

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.



139
140
141
# File 'app/models/concerns/katalyst/content/container.rb', line 139

def items_attributes=(attributes)
  next_version.nodes = attributes
end

#publish!Object

Promotes the draft version to become the published version



112
113
114
115
# File 'app/models/concerns/katalyst/content/container.rb', line 112

def publish!
  update!(published_version: draft_version)
  self
end

#revert!Object

Reverts the draft version to the current published version



118
119
120
121
# File 'app/models/concerns/katalyst/content/container.rb', line 118

def revert!
  update!(draft_version: published_version)
  self
end

#unpublish!Object

Sets the currently published version to nil



124
125
126
127
# File 'app/models/concerns/katalyst/content/container.rb', line 124

def unpublish!
  update!(published_version_id: nil)
  self
end