Class: SubmissionTemplate
Overview
It associates a name to a pre-filled submission (subclass) and a serialized set of attributes We could have use a Prototype Factory , and so just associate a name to existing submission but that doesn’t work because the submission prototype doesn’t pass the validation stage. Anyway that’s basically a prototype factory
Constant Summary
collapse
- LATEST_VERSION =
-1
- SUPERCEDED_BY_UNKNOWN_TEMPLATE =
-2
Class Method Summary
collapse
Instance Method Summary
collapse
included, #unsaved_uuid!, #uuid
alias_association, convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!
Methods included from Squishify
extended
Class Method Details
.grouped_by_product_lines ⇒ Object
33
34
35
|
# File 'app/models/submission_template.rb', line 33
def self.grouped_by_product_lines
visible.include_product_line.group_by { |t| t.product_line.try(:name) || 'General' }
end
|
Instance Method Details
#create_order!(attributes) ⇒ Object
57
58
59
60
61
62
|
# File 'app/models/submission_template.rb', line 57
def create_order!(attributes)
new_order(attributes).tap do |order|
yield(order) if block_given?
order.save!
end
end
|
#create_with_submission!(attributes = {}) ⇒ Object
64
65
66
|
# File 'app/models/submission_template.rb', line 64
def create_with_submission!(attributes = {})
create_order!(attributes) { |order| order.create_submission(user_id: order.user_id) }
end
|
95
96
97
|
# File 'app/models/submission_template.rb', line 95
def input_asset_type
sorted_request_types.first.asset_type
end
|
99
100
101
|
# File 'app/models/submission_template.rb', line 99
def input_plate_purposes
sorted_request_types.first.acceptable_purposes
end
|
#new_order(params = {}) ⇒ Object
create a new submission of the good subclass and with pre-set attributes
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'app/models/submission_template.rb', line 69
def new_order(params = {})
duped_params = safely_duplicate(params)
attributes = submission_attributes.with_indifferent_access.deep_merge(duped_params)
submission_class
.new(attributes)
.tap do |order|
order.template_name = name
order.product = product_for(attributes)
end
end
|
#sequencing? ⇒ Boolean
91
92
93
|
# File 'app/models/submission_template.rb', line 91
def sequencing?
request_types.any?(&:sequencing)
end
|
#submission_class ⇒ Object
83
84
85
|
# File 'app/models/submission_template.rb', line 83
def submission_class
submission_class_name.constantize
end
|
#supercede ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
|
# File 'app/models/submission_template.rb', line 45
def supercede
ActiveRecord::Base.transaction do
dup.tap do |cloned|
yield(cloned) if block_given?
name, cloned.name = cloned.name, "Superceding #{cloned.name}"
cloned.save!
update!(superceded_by_id: cloned.id, superceded_at: Time.zone.now)
cloned.update!(name:)
end
end
end
|
#superceded_by_unknown! ⇒ Object
#visible ⇒ Object
37
38
39
|
# File 'app/models/submission_template.rb', line 37
def visible
superceded_by_id == LATEST_VERSION
end
|