Class: Wallaby::ActiveRecord::ModelOperator::Validator
- Inherits:
-
Object
- Object
- Wallaby::ActiveRecord::ModelOperator::Validator
- Defined in:
- lib/adaptors/wallaby/active_record/model_operator/validator.rb
Instance Method Summary collapse
-
#initialize(model_decorator) ⇒ Validator
constructor
A new instance of Validator.
- #valid?(resource) ⇒ Boolean
Constructor Details
#initialize(model_decorator) ⇒ Validator
Returns a new instance of Validator.
2 3 4 |
# File 'lib/adaptors/wallaby/active_record/model_operator/validator.rb', line 2 def initialize(model_decorator) @model_decorator = model_decorator end |
Instance Method Details
#valid?(resource) ⇒ Boolean
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/adaptors/wallaby/active_record/model_operator/validator.rb', line 6 def valid?(resource) resource.attributes.each do |field_name, values| next unless = @model_decorator.fields[field_name] if %w( daterange tsrange tstzrange ).include?([:type]) && values.try(:any?, &:blank?) resource.errors.add field_name, 'required for range data' end end resource.errors.blank? end |