Class: ComposedValidations::WithValidatedProperty
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- ComposedValidations::WithValidatedProperty
- Defined in:
- lib/composed_validations/with_validated_property.rb
Instance Attribute Summary collapse
-
#property ⇒ Object
readonly
Returns the value of attribute property.
-
#validator ⇒ Object
readonly
Returns the value of attribute validator.
Instance Method Summary collapse
- #class ⇒ Object
-
#initialize(resource, property, validator) ⇒ WithValidatedProperty
constructor
A new instance of WithValidatedProperty.
- #save(*args) ⇒ Object
- #valid?(*args) ⇒ Boolean
Constructor Details
#initialize(resource, property, validator) ⇒ WithValidatedProperty
Returns a new instance of WithValidatedProperty.
4 5 6 7 8 |
# File 'lib/composed_validations/with_validated_property.rb', line 4 def initialize(resource, property, validator) super(resource) @property = ComposedValidations::ValidatedProperty(property) @validator = validator end |
Instance Attribute Details
#property ⇒ Object (readonly)
Returns the value of attribute property.
3 4 5 |
# File 'lib/composed_validations/with_validated_property.rb', line 3 def property @property end |
#validator ⇒ Object (readonly)
Returns the value of attribute validator.
3 4 5 |
# File 'lib/composed_validations/with_validated_property.rb', line 3 def validator @validator end |
Instance Method Details
#class ⇒ Object
10 11 12 |
# File 'lib/composed_validations/with_validated_property.rb', line 10 def class __getobj__.class end |
#save(*args) ⇒ Object
22 23 24 25 |
# File 'lib/composed_validations/with_validated_property.rb', line 22 def save(*args) return false unless valid? __getobj__.save(*args) end |
#valid?(*args) ⇒ Boolean
14 15 16 17 18 19 20 |
# File 'lib/composed_validations/with_validated_property.rb', line 14 def valid?(*args) __getobj__.valid?(*args) unless validator.valid_value?(result) errors.add(property.validated_property, validator.) end errors.blank? end |