Sha256: 95f1e145db6050ca4e3cf27d4f1171256b325da78789e55fb8fb2f9d89457e62

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module Lcms
  module Engine
    class MaterialForm
      include Virtus.model
      include ActiveModel::Model
      include Lcms::Engine::GoogleCredentials

      attribute :link, String
      attribute :source_type, String
      validates :link, presence: true

      attr_accessor :material

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

      def save
        return false unless valid?

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

        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

      private

      attr_reader :options

      protected

      def after_reimport_hook; end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lcms-engine-0.2.0 app/forms/lcms/engine/material_form.rb
lcms-engine-0.1.2 app/forms/lcms/engine/material_form.rb
lcms-engine-0.1.0 app/forms/lcms/engine/material_form.rb