Class: Lcms::Engine::MaterialForm

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, GoogleCredentials
Defined in:
app/forms/lcms/engine/material_form.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}, opts = {}) ⇒ MaterialForm

Returns a new instance of MaterialForm.



16
17
18
19
# File 'app/forms/lcms/engine/material_form.rb', line 16

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

Instance Attribute Details

#materialObject

Returns the value of attribute material.



14
15
16
# File 'app/forms/lcms/engine/material_form.rb', line 14

def material
  @material
end

#service_errorsObject

Returns the value of attribute service_errors.



14
15
16
# File 'app/forms/lcms/engine/material_form.rb', line 14

def service_errors
  @service_errors
end

Instance Method Details

#saveObject



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

def save
  return false unless valid?

  params = {
    dpi: options[:dpi],
    import_retry: options[:import_retry],
    source_type: source_type.presence
  }.compact
  service = MaterialBuildService.new google_credentials, params
  @material = service.build link
  @service_errors = service.errors

  material.update preview_links: {}
  after_reimport_hook
  true
rescue StandardError => e
  Rails.logger.error "#{e.message}\n #{e.backtrace.join("\n ")}"
  errors.add(:link, e.message)
  false
end