Class: Lcms::Engine::DocumentBuildService

Inherits:
Object
  • Object
show all
Defined in:
app/services/lcms/engine/document_build_service.rb

Constant Summary collapse

EVENT_BUILT =
'document:built'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(credentials, opts = {}) ⇒ DocumentBuildService

Returns a new instance of DocumentBuildService.



12
13
14
15
16
# File 'app/services/lcms/engine/document_build_service.rb', line 12

def initialize(credentials, opts = {})
  @credentials = credentials
  @errors = []
  @options = opts
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



10
11
12
# File 'app/services/lcms/engine/document_build_service.rb', line 10

def errors
  @errors
end

Instance Method Details

#build_for(url, expand: false) ⇒ Object

Returns Document ActiveRecord::Model.

Returns:

  • Document ActiveRecord::Model



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/services/lcms/engine/document_build_service.rb', line 21

def build_for(url, expand: false)
  @content = download url
  @expand_document = expand
  @template = DocTemplate::Template.parse @content
  @errors = @template..errors

  create_document
  clear_preview_link

  content_key = foundational? ? :foundational_content : :original_content
  @document.update! content_key => content

  build
  @document.create_parts_for(template)

  ActiveSupport::Notifications.instrument EVENT_BUILT, id: document.id

  document.activate!
  document
end