Class: Validacity::BaseValidation
- Inherits:
-
Object
- Object
- Validacity::BaseValidation
show all
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/validacity/base_validation.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of BaseValidation.
17
18
19
|
# File 'lib/validacity/base_validation.rb', line 17
def initialize(resource)
@resource = resource
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *attrs, &block) ⇒ Object
29
30
31
|
# File 'lib/validacity/base_validation.rb', line 29
def method_missing(name, *attrs, &block)
@resource.public_send(name, *attrs, &block)
end
|
Class Method Details
.inherited(klass) ⇒ Object
6
7
8
|
# File 'lib/validacity/base_validation.rb', line 6
def inherited(klass)
Validacity.validations[validation_name(klass)] = klass
end
|
Instance Method Details
#respond_to?(name) ⇒ Boolean
21
22
23
|
# File 'lib/validacity/base_validation.rb', line 21
def respond_to?(name)
@resource.respond_to?(method)
end
|
#respond_to_missing? ⇒ Boolean
25
26
27
|
# File 'lib/validacity/base_validation.rb', line 25
def respond_to_missing?
true
end
|
#validate ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/validacity/base_validation.rb', line 33
def validate
return true if valid?
errors.each do |field, error|
@resource.errors[field] << error
end
false
end
|
#validate! ⇒ Object
43
44
45
|
# File 'lib/validacity/base_validation.rb', line 43
def validate!
validate or raise ActiveModel::ValidationError, @resource
end
|