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 Method Summary collapse

Constructor Details

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

Returns a new instance of DocumentBuildService.



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

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

Instance Method Details

#build_for(url, expand: false) ⇒ Object

Returns Document ActiveRecord::Model.

Returns:

  • Document ActiveRecord::Model



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

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

  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