Class: Statinize::Validation
Constant Summary collapse
- INSTANCE_METHODS =
%i[validate validate! valid? invalid? errors]
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
-
#statinizer ⇒ Object
readonly
Returns the value of attribute statinizer.
Instance Method Summary collapse
-
#initialize(statinizer, instance) ⇒ Validation
constructor
A new instance of Validation.
- #invalid? ⇒ Boolean
- #valid? ⇒ Boolean
- #validate ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(statinizer, instance) ⇒ Validation
Returns a new instance of Validation.
7 8 9 10 11 12 |
# File 'lib/statinize/validation.rb', line 7 def initialize(statinizer, instance) @statinizer = statinizer @instance = instance define_instance_methods end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
5 6 7 |
# File 'lib/statinize/validation.rb', line 5 def errors @errors end |
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
5 6 7 |
# File 'lib/statinize/validation.rb', line 5 def instance @instance end |
#statinizer ⇒ Object (readonly)
Returns the value of attribute statinizer.
5 6 7 |
# File 'lib/statinize/validation.rb', line 5 def statinizer @statinizer end |
Instance Method Details
#invalid? ⇒ Boolean
32 33 34 |
# File 'lib/statinize/validation.rb', line 32 def invalid? !valid? end |
#valid? ⇒ Boolean
28 29 30 |
# File 'lib/statinize/validation.rb', line 28 def valid? errors.empty? end |
#validate ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/statinize/validation.rb', line 14 def validate @errors = Errors.new { |h, k| h[k] = [] } @erroneous_attributes = Hash.new { |h, k| h[k] = Set.new } @erroneous_forced_attributes = Hash.new { |h, k| h[k] = Set.new } fill_errors end |
#validate! ⇒ Object
22 23 24 25 26 |
# File 'lib/statinize/validation.rb', line 22 def validate! validate raise ValidationError, errors.nice if should_raise? end |