Class: LicenseValidator::Validations::Base
- Inherits:
-
Object
- Object
- LicenseValidator::Validations::Base
- Extended by:
- ActiveModel::Naming
- Defined in:
- lib/license_validator/validations/base.rb
Direct Known Subclasses
StateAk, StateAl, StateAr, StateAz, StateCa, StateCo, StateCt, StateDc, StateDe, StateFl, StateGa, StateHi, StateIa, StateId, StateIl, StateIn, StateKs, StateKy, StateLa, StateMa, StateMd, StateMe, StateMi, StateMn, StateMo, StateMs, StateMt, StateNc, StateNd, StateNe, StateNh, StateNj, StateNm, StateNv, StateNy, StateOh, StateOk, StateOr, StatePa, StateRi, StateSc, StateSd, StateTn, StateTx, StateUt, StateVa, StateVt, StateWa, StateWi, StateWv, StateWy
Instance Attribute Summary collapse
- #driver ⇒ LicenseValidator::Driver
- #errors ⇒ ActiveModel::Errors
- #infos ⇒ ActiveModel::Errors
- #warnings ⇒ ActiveModel::Errors
Class Method Summary collapse
-
.human_attribute_name(attr, _options = {}) ⇒ Object
Necessary for ActiveModel::Errors api.rubyonrails.org/classes/ActiveModel/Errors.html.
-
.lookup_ancestors ⇒ Object
Necessary for ActiveModel::Errors api.rubyonrails.org/classes/ActiveModel/Errors.html.
Instance Method Summary collapse
-
#initialize(driver) ⇒ Base
constructor
A new instance of Base.
-
#read_attribute_for_validation(attr) ⇒ Object
Necessary for ActiveModel::Errors api.rubyonrails.org/classes/ActiveModel/Errors.html.
-
#validate ⇒ Object
Common validations.
- #validation_results ⇒ Hash
Constructor Details
#initialize(driver) ⇒ Base
Returns a new instance of Base.
30 31 32 33 34 35 36 |
# File 'lib/license_validator/validations/base.rb', line 30 def initialize(driver) @errors = ActiveModel::Errors.new(self) @warnings = ActiveModel::Errors.new(self) @infos = ActiveModel::Errors.new(self) @driver = driver end |
Instance Attribute Details
#driver ⇒ LicenseValidator::Driver
9 10 11 |
# File 'lib/license_validator/validations/base.rb', line 9 def driver @driver end |
#errors ⇒ ActiveModel::Errors
11 12 13 |
# File 'lib/license_validator/validations/base.rb', line 11 def errors @errors end |
#infos ⇒ ActiveModel::Errors
13 14 15 |
# File 'lib/license_validator/validations/base.rb', line 13 def infos @infos end |
#warnings ⇒ ActiveModel::Errors
15 16 17 |
# File 'lib/license_validator/validations/base.rb', line 15 def warnings @warnings end |
Class Method Details
.human_attribute_name(attr, _options = {}) ⇒ Object
Necessary for ActiveModel::Errors api.rubyonrails.org/classes/ActiveModel/Errors.html
24 25 26 |
# File 'lib/license_validator/validations/base.rb', line 24 def human_attribute_name(attr, = {}) attr end |
.lookup_ancestors ⇒ Object
Necessary for ActiveModel::Errors api.rubyonrails.org/classes/ActiveModel/Errors.html
19 20 21 |
# File 'lib/license_validator/validations/base.rb', line 19 def lookup_ancestors [self] end |
Instance Method Details
#read_attribute_for_validation(attr) ⇒ Object
Necessary for ActiveModel::Errors api.rubyonrails.org/classes/ActiveModel/Errors.html
39 40 41 |
# File 'lib/license_validator/validations/base.rb', line 39 def read_attribute_for_validation(attr) __send__(attr) end |
#validate ⇒ Object
Common validations
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/license_validator/validations/base.rb', line 44 def validate return if driver.dob.nil? age = driver.age if age < 21 warnings.add(:dob, 'Drivers under 21 do not qualify for an interstate CDL.') elsif age < 23 warnings.add( :dob, 'Drivers under 23 are underage for all markets unless underwriters have specifically approved.' ) elsif age > 65 warnings.add( :dob, [ 'Drivers is older than 65, check underwriting guidelines to determine if they should be submitted', 'for approval.' ].join(' ') ) end return unless driver.bad warnings.add(:bad, 'Driver is on the bad drivers list.') end |
#validation_results ⇒ Hash
72 73 74 75 76 77 78 79 |
# File 'lib/license_validator/validations/base.rb', line 72 def validation_results { errors: errors, warnings: warnings, infos: infos, validated_with: driver.attributes } end |