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 ⇒ Object
- #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
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 |
#print_job ⇒ Object
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 |
#print_job_message ⇒ Object
63 64 65 |
# File 'app/models/sample_manifest/generator.rb', line 63 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 |