Class: Fulcrum::BaseValidator
- Inherits:
-
Object
- Object
- Fulcrum::BaseValidator
- Defined in:
- lib/fulcrum/validators/base_validator.rb
Direct Known Subclasses
ChoiceListValidator, ClassificationSetValidator, FormValidator, RecordValidator
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#errors ⇒ Object
Returns the value of attribute errors.
Instance Method Summary collapse
- #add_error(key, data_name, error) ⇒ Object
-
#initialize(data) ⇒ BaseValidator
constructor
A new instance of BaseValidator.
- #valid? ⇒ Boolean
Constructor Details
#initialize(data) ⇒ BaseValidator
Returns a new instance of BaseValidator.
8 9 10 11 12 |
# File 'lib/fulcrum/validators/base_validator.rb', line 8 def initialize(data) @data = (data.is_a?(Hash) ? data : JSON.parse(data)).with_indifferent_access @errors = {} validate! end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/fulcrum/validators/base_validator.rb', line 5 def data @data end |
#errors ⇒ Object
Returns the value of attribute errors.
6 7 8 |
# File 'lib/fulcrum/validators/base_validator.rb', line 6 def errors @errors end |
Instance Method Details
#add_error(key, data_name, error) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fulcrum/validators/base_validator.rb', line 18 def add_error(key, data_name, error) if errors.has_key?(key) if errors[key].has_key?(data_name) errors[key][data_name].push(error) else errors[key][data_name] = [error] end else errors[key] = {} errors[key][data_name] = [error] end end |
#valid? ⇒ Boolean
14 15 16 |
# File 'lib/fulcrum/validators/base_validator.rb', line 14 def valid? errors.empty? end |