Class: RivetCms::DraftWriter

Inherits:
Object
  • Object
show all
Defined in:
app/services/rivet_cms/draft_writer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(revision) ⇒ DraftWriter

Returns a new instance of DraftWriter.



7
8
9
10
# File 'app/services/rivet_cms/draft_writer.rb', line 7

def initialize(revision)
  @revision = revision
  @dropped_references = 0
end

Instance Attribute Details

#dropped_referencesObject (readonly)

References whose target was trashed are dropped on save; the caller reports that rather than letting the link vanish silently.



5
6
7
# File 'app/services/rivet_cms/draft_writer.rb', line 5

def dropped_references
  @dropped_references
end

Instance Method Details

#write(values) ⇒ Object

Raises:



12
13
14
15
16
17
18
19
20
# File 'app/services/rivet_cms/draft_writer.rb', line 12

def write(values)
  raise TrashedEntryError, "entry is in the trash; restore it before editing" if @revision.document.nil?

  content_type = @revision.document.content_type
  raise RemovedContentTypeError, "content type was removed; restore it before editing" if content_type.nil?

  write_values(@revision, content_type.fields.kept, values)
  @revision
end