Class: OrderCompatibilityValidator

Inherits:
ActiveModel::Validator
  • Object
show all
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

Returns:

  • (Boolean)

20
21
22
# File 'app/validators/order_compatibility_validator.rb', line 20

def read_lengths_identical?(orders)
  orders.collect { |order| order.request_options['read_length'] }.uniq.length == 1
end

#validate(record) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
# 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? { |request_types| request_types.post_for_multiplexing == order_request_types.first.post_for_multiplexing }
end