Class: RequestType::Validator

Inherits:
ApplicationRecord show all
Defined in:
app/models/request_type/validator.rb

Overview

A request type validator belongs to a request type, and is responsible for validating a single request option request_option => The option that will be validated valid_options => A serialized object that responds to include? Returning true if the option is present

It should also return an array of valid options in response to to_a

Defined Under Namespace

Classes: ArrayWithDefault, LibraryTypeValidator, NullValidator

Instance Method Summary collapse

Methods inherited from ApplicationRecord

convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Squishify

extended

Instance Method Details

#defaultObject


89
90
91
# File 'app/models/request_type/validator.rb', line 89

def default
  valid_options.respond_to?(:default) ? valid_options.default : nil
end

#optionsObject


85
86
87
# File 'app/models/request_type/validator.rb', line 85

def options
  valid_options.to_a
end

#type_castObject


93
94
95
# File 'app/models/request_type/validator.rb', line 93

def type_cast
  { 'read_length' => :to_i, 'insert_size' => :to_i }[request_option]
end

#validate?(value) ⇒ Boolean

Returns:

  • (Boolean)

81
82
83
# File 'app/models/request_type/validator.rb', line 81

def validate?(value)
  valid_options.include?(value)
end