Class: GaggedValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/ball_gag/validations.rb

Direct Known Subclasses

NotGaggedValidator

Instance Method Summary collapse

Instance Method Details

#validate_each(object, attribute, value) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/ball_gag/validations.rb', line 2

def validate_each object, attribute, value
  if BallGag.only_validate_on_attribute_changed
    dirty_method_name = "#{attribute}_changed?"
    if object.respond_to?(dirty_method_name)
      return unless object.method(dirty_method_name).call
    end
  end

  unless object.method(condition_method_name(attribute)).call
    object.errors[attribute] << (options[:message] || default_message)
  end
end