Class: SampleManifest::Generator
- Inherits:
-
Object
- Object
- SampleManifest::Generator
- 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
Constant Summary collapse
- REQUIRED_ATTRIBUTES =
%w[template count].freeze
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#sample_manifest ⇒ Object
readonly
Returns the value of attribute sample_manifest.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
- #columns ⇒ Object
-
#execute ⇒ Object
rubocop:todo Metrics/MethodLength.
-
#initialize(params, user, configuration) ⇒ Generator
constructor
A new instance of Generator.
-
#print_job ⇒ LabelPrinter::PrintJob
Creates and returns a print job for the sample manifest.
- #print_job_message ⇒ Object
- #print_job_required? ⇒ Boolean
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
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
14 15 16 |
# File 'app/models/sample_manifest/generator.rb', line 14 def configuration @configuration end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
14 15 16 |
# File 'app/models/sample_manifest/generator.rb', line 14 def params @params end |
#sample_manifest ⇒ Object (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 |
#user ⇒ Object (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_name ⇒ Object
21 22 23 |
# File 'app/models/sample_manifest/generator.rb', line 21 def self.model_name ActiveModel::Name.new(SampleManifest) end |
Instance Method Details
#columns ⇒ Object
31 32 33 |
# File 'app/models/sample_manifest/generator.rb', line 31 def columns @columns ||= configuration.columns.find(params[:template]) end |
#execute ⇒ Object
rubocop:todo Metrics/MethodLength
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/models/sample_manifest/generator.rb', line 75 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 |
#print_job ⇒ LabelPrinter::PrintJob
Creates and returns a print job for the sample manifest.
This method initializes a new LabelPrinter::PrintJob
object with the provided parameters. The print job is responsible for printing labels for the sample manifest, using the specified barcode printer and label template.
Parameters used: - params[:barcode_printer]
: The barcode printer to use for printing. - LabelPrinter::Label::SampleManifestRedirect
: The label type for the sample manifest. - only_first_label
: A boolean indicating whether only the first label should be printed. - sample_manifest
: The sample manifest object for which labels are being printed. - label_template_name
: The label template to use, determined by label_template_for_2d_barcodes
. If not given, the template given in the database is used. - params[:barcode_type]
: The type of barcode being used.
Example: print_job # => #<LabelPrinter::PrintJob:0x00007f8c8c1b2e10>
Caching: - The method memoizes the print job object in the @print_job
instance variable to avoid creating multiple instances for the same parameters.
63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/models/sample_manifest/generator.rb', line 63 def print_job @print_job ||= LabelPrinter::PrintJob.new( params[:barcode_printer], LabelPrinter::Label::SampleManifestRedirect, only_first_label: only_first_label, sample_manifest: sample_manifest, label_template_name: , barcode_type: params[:barcode_type] ) end |
#print_job_message ⇒ Object
89 90 91 |
# File 'app/models/sample_manifest/generator.rb', line 89 def @print_job_message ||= {} end |
#print_job_required? ⇒ Boolean
35 36 37 |
# File 'app/models/sample_manifest/generator.rb', line 35 def print_job_required? params[:barcode_printer].present? end |