Class: OrderCompatibilityValidator
- Inherits:
-
ActiveModel::Validator
- Object
- ActiveModel::Validator
- OrderCompatibilityValidator
- Defined in:
- app/validators/order_compatibility_validator.rb
Overview
Orders are compatible if:
-
all of the read lengths are identical
-
all of the request types are not for mutliplexing or
-
all of the request types post the multiplexing request are the same
Defined Under Namespace
Classes: OrderRequestTypes
Instance Method Summary collapse
Instance Method Details
#read_lengths_identical?(orders) ⇒ Boolean
22 23 24 |
# File 'app/validators/order_compatibility_validator.rb', line 22 def read_lengths_identical?(orders) orders.collect { |order| order.['read_length'] }.uniq.length == 1 end |
#validate(record) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/validators/order_compatibility_validator.rb', line 8 def validate(record) orders = record.orders return if orders.size < 2 record.errors.add(:orders, 'are incompatible') unless read_lengths_identical?(orders) order_request_types = orders.collect { |order| OrderRequestTypes.new(order.request_types) } return if order_request_types.all?(&:not_for_multiplexing?) record.errors.add(:orders, 'are incompatible') if order_request_types.any?(&:not_for_multiplexing?) record.errors.add(:orders, 'are incompatible') unless order_request_types.all? do |request_types| request_types.post_for_multiplexing == order_request_types.first.post_for_multiplexing end end |