Class: ComposedValidations::WithValidatedProperty

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/composed_validations/with_validated_property.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#propertyObject (readonly)

Returns the value of attribute property.



3
4
5
# File 'lib/composed_validations/with_validated_property.rb', line 3

def property
  @property
end

#validatorObject (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

#classObject



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

Returns:

  • (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.message)
  end
  errors.blank?
end