Class: Fintecture::Utils::Validation
- Inherits:
-
Object
- Object
- Fintecture::Utils::Validation
- Defined in:
- lib/fintecture/utils/validation.rb
Class Method Summary collapse
- .raise_if_invalid_date_format(date) ⇒ Object
- .raise_if_klass_mismatch(target, klass, param_name = nil) ⇒ Object
Class Method Details
.raise_if_invalid_date_format(date) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fintecture/utils/validation.rb', line 16 def raise_if_invalid_date_format(date) return unless date valid_format = date.match(/\d{4}-\d{2}-\d{2}/) valid_date = begin ::Date.strptime(date, '%Y-%m-%d') rescue StandardError false end return if valid_format && valid_date raise Fintecture::ValidationException, "invalidss #{date} date, the format should be YYYY-MM-DD" end |
.raise_if_klass_mismatch(target, klass, param_name = nil) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/fintecture/utils/validation.rb', line 9 def raise_if_klass_mismatch(target, klass, param_name = nil) return if target.is_a? klass raise Fintecture::ValidationException, "invalid #{param_name || 'parameter'} format, the parameter should be a #{klass} instead a #{target.class.name}" end |