Class: RequestType
Overview
orders use RequestTypes as a factory to construct requests. The list of request types to use is provided by Order#request_types and usually gets populated by the SubmissionTemplate. Once the request is built, request type identifies the type of Request and associates it with a particular Pipeline. In the case of external pipelines, such as Limber, other properties of Request such as its LibraryType may also be considered. Request types have associated validators which will be used to ensure that the associated requests have compatible Metadata::Metadata. In the case of library types, this uses the library_types association on the request type to provide the list of compatible library types. Currently the request type is also the means of associating the request with a particular team (product line) however this may belong better on request itself, and could be set either on the basis of the submission template used, or by a new ‘team’ option on the submission itself.
Defined Under Namespace
Modules: Validation
Classes: DeprecatedError, PoolingMethod, RequestTypePlatePurpose, Validator
Constant Summary
collapse
- MORPHOLOGIES =
[
LINEAR = 0, CONVERGENT = 1, DIVERGENT = 2 ].freeze
Instance Attribute Summary collapse
-
#key ⇒ String
A simple text identifier for the request type designed for programmatic use.
Class Method Summary
collapse
Instance Method Summary
collapse
included
included, #unsaved_uuid!, #uuid
Methods included from Validation
#create_validator, #delegate_validator, #request_type_validator
alias_association, convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!
Methods included from Squishify
extended
Instance Attribute Details
#key ⇒ String
Returns A simple text identifier for the request type designed for programmatic use.
46
|
# File 'app/models/request_type.rb', line 46
has_many :requests, inverse_of: :request_type
|
Class Method Details
.create_asset ⇒ Object
127
128
129
130
131
132
133
134
135
|
# File 'app/models/request_type.rb', line 127
def self.create_asset
create_with(
name: 'Create Asset',
order: 1,
asset_type: 'Asset',
request_class_name: 'CreateAssetRequest',
request_purpose: :internal
).find_or_create_by!(key: 'create_asset')
end
|
.external_multiplexed_library_creation ⇒ Object
137
138
139
140
141
142
143
144
145
146
147
|
# File 'app/models/request_type.rb', line 137
def self.external_multiplexed_library_creation
create_with(
asset_type: 'LibraryTube',
for_multiplexing: true,
initial_state: 'pending',
order: 0,
name: 'External Multiplexed Library Creation',
request_class_name: 'ExternalLibraryCreationRequest',
request_purpose: :standard
).find_or_create_by!(key: 'external_multiplexed_library_creation')
end
|
Instance Method Details
#construct_request(construct_method, attributes, klass = request_class) ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'app/models/request_type.rb', line 100
def construct_request(construct_method, attributes, klass = request_class)
raise RequestType::DeprecatedError if deprecated?
new_request =
klass.public_send(construct_method, attributes) do |request|
request.request_type = self
request.request_purpose ||= request_purpose
yield(request) if block_given?
end
requests.reset
new_request
end
|
#create!(attributes = {}) ⇒ Object
115
116
117
|
# File 'app/models/request_type.rb', line 115
def create!(attributes = {}, &)
construct_request(:create!, attributes, &)
end
|
#create_control!(attributes = {}) ⇒ Object
123
124
125
|
# File 'app/models/request_type.rb', line 123
def create_control!(attributes = {}, &)
construct_request(:create!, attributes, ControlRequest, &)
end
|
#create_target_asset! ⇒ Object
175
176
177
178
179
180
181
182
183
184
|
# File 'app/models/request_type.rb', line 175
def create_target_asset!(&)
case
when target_purpose.present?
target_purpose.create!(&).receptacle
when target_asset_type.blank?
nil
else
target_asset_type.constantize.create!(&)
end
end
|
#default_library_type ⇒ Object
186
187
188
|
# File 'app/models/request_type.rb', line 186
def default_library_type
library_types.find_by(library_types_request_types: { is_default: true })
end
|
165
166
167
168
169
170
171
172
173
|
# File 'app/models/request_type.rb', line 165
def (request_options)
return {} unless request_options
attributes = request_options.symbolize_keys
common_attributes = request_class::Metadata.attribute_details.map(&:name)
common_attributes.concat(request_class::Metadata.association_details.map(&:assignable_attribute_name))
attributes.delete_if { |k, _| common_attributes.exclude?(k) }
end
|
#new(attributes = {}) ⇒ Object
119
120
121
|
# File 'app/models/request_type.rb', line 119
def new(attributes = {}, &)
construct_request(:new, attributes, &)
end
|
#product_line_name=(product_line_name) ⇒ Object
157
158
159
|
# File 'app/models/request_type.rb', line 157
def product_line_name=(product_line_name)
self.product_line = ProductLine.find_or_create_by!(name: product_line_name)
end
|
#request_attributes ⇒ Object
199
200
201
|
# File 'app/models/request_type.rb', line 199
def request_attributes
request_class::Metadata.attribute_details + request_class::Metadata.association_details
end
|
#request_class ⇒ Object
149
150
151
|
# File 'app/models/request_type.rb', line 149
def request_class
request_class_name&.constantize
end
|
#request_class=(request_class) ⇒ Object
153
154
155
|
# File 'app/models/request_type.rb', line 153
def request_class=(request_class)
self.request_class_name = request_class.name
end
|
#target_purpose_name=(target_purpose_name) ⇒ Object
161
162
163
|
# File 'app/models/request_type.rb', line 161
def target_purpose_name=(target_purpose_name)
self.target_purpose = Purpose.find_by!(name: target_purpose_name)
end
|
#validator_for(request_option) ⇒ Object
Returns the validator for a given option.
191
192
193
194
195
196
197
|
# File 'app/models/request_type.rb', line 191
def validator_for(request_option)
if request_type_validators.loaded?
request_type_validators.detect { |rtv| rtv.request_option == request_option.to_s }
else
request_type_validators.find_by(request_option: request_option.to_s)
end || RequestType::Validator::NullValidator.new
end
|