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_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.



78
79
80
# File 'app/models/concerns/katalyst/content/container.rb', line 78

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

#publish!Object

Promotes the draft version to become the published version



62
63
64
65
# File 'app/models/concerns/katalyst/content/container.rb', line 62

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

#revert!Object

Reverts the draft version to the current published version



68
69
70
71
# File 'app/models/concerns/katalyst/content/container.rb', line 68

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

#stateObject

A resource is in draft mode if it has an unpublished draft or it has no published version.

Returns:

  • the current state of the resource, either published or draft



53
54
55
56
57
58
59
# File 'app/models/concerns/katalyst/content/container.rb', line 53

def state
  if published_version_id && published_version_id == draft_version_id
    :published
  else
    :draft
  end
end