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



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

Returns:

  • (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

#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`



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