Class: SampleManifest::Generator

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
app/models/sample_manifest/generator.rb

Overview

Class SampleManifest::Generator provides an interface for generating sample manifests from the controller

Author:

  • Genome Research Ltd.

Constant Summary collapse

REQUIRED_ATTRIBUTES =
%w[template count].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, user, configuration) ⇒ Generator

Returns a new instance of Generator.



25
26
27
28
29
# File 'app/models/sample_manifest/generator.rb', line 25

def initialize(params, user, configuration)
  @configuration = configuration
  @user = user
  @params = params
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



14
15
16
# File 'app/models/sample_manifest/generator.rb', line 14

def configuration
  @configuration
end

#paramsObject (readonly)

Returns the value of attribute params.



14
15
16
# File 'app/models/sample_manifest/generator.rb', line 14

def params
  @params
end

#sample_manifestObject (readonly)

Returns the value of attribute sample_manifest.



14
15
16
# File 'app/models/sample_manifest/generator.rb', line 14

def sample_manifest
  @sample_manifest
end

#userObject (readonly)

Returns the value of attribute user.



14
15
16
# File 'app/models/sample_manifest/generator.rb', line 14

def user
  @user
end

Class Method Details

.model_nameObject



21
22
23
# File 'app/models/sample_manifest/generator.rb', line 21

def self.model_name
  ActiveModel::Name.new(SampleManifest)
end

Instance Method Details

#columnsObject



31
32
33
# File 'app/models/sample_manifest/generator.rb', line 31

def columns
  @columns ||= configuration.columns.find(params[:template])
end

#executeObject

rubocop:todo Metrics/MethodLength



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/sample_manifest/generator.rb', line 49

def execute # rubocop:todo Metrics/MethodLength
  if valid?
    ActiveRecord::Base.transaction do
      @sample_manifest = SampleManifest.create!(attributes)
      sample_manifest.generate
      create_download
      execute_print_job
      true
    end
  else
    false
  end
end


39
40
41
42
43
44
45
46
47
# File 'app/models/sample_manifest/generator.rb', line 39

def print_job
  @print_job ||=
    LabelPrinter::PrintJob.new(
      params[:barcode_printer],
      LabelPrinter::Label::SampleManifestRedirect,
      only_first_label:,
      sample_manifest:
    )
end


63
64
65
# File 'app/models/sample_manifest/generator.rb', line 63

def print_job_message
  @print_job_message ||= {}
end

Returns:

  • (Boolean)


35
36
37
# File 'app/models/sample_manifest/generator.rb', line 35

def print_job_required?
  params[:barcode_printer].present?
end