class Validacity::BaseValidation
Public Class Methods
inherited(klass)
click to toggle source
# File lib/validacity/base_validation.rb, line 6 def inherited(klass) Validacity.validations[validation_name(klass)] = klass end
new(resource)
click to toggle source
# File lib/validacity/base_validation.rb, line 17 def initialize(resource) @resource = resource end
Private Class Methods
validation_name(klass)
click to toggle source
# File lib/validacity/base_validation.rb, line 12 def validation_name(klass) klass.name.gsub(/Validation$/, "").underscore.to_sym end
Public Instance Methods
method_missing(name, *attrs, &block)
click to toggle source
# File lib/validacity/base_validation.rb, line 29 def method_missing(name, *attrs, &block) @resource.public_send(name, *attrs, &block) end
respond_to?(name)
click to toggle source
# File lib/validacity/base_validation.rb, line 21 def respond_to?(name) @resource.respond_to?(method) end
respond_to_missing?()
click to toggle source
# File lib/validacity/base_validation.rb, line 25 def respond_to_missing? true end
validate()
click to toggle source
# 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!()
click to toggle source
# File lib/validacity/base_validation.rb, line 43 def validate! validate or raise ActiveModel::ValidationError, @resource end