Module: ValidationSets::InstanceMethods

Included in:
ActiveRecord::Base
Defined in:
lib/validation_sets.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_validation_setObject (readonly)

Returns the value of attribute _validation_set.



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

def _validation_set
  @_validation_set
end

Instance Method Details

#use_validation_set(set) ⇒ Object

Set the active validation set on the model. After calling this both the global as well as the validations defined in the set will run.

Raises an exception when asked to use an unknown validation set.

Example:

 = Account.new
.use_validation_set(:admin) # Turns on the :admin validation set
.use_validation_set(nil)    # Turns off all validation sets


15
16
17
18
19
20
21
# File 'lib/validation_sets.rb', line 15

def use_validation_set(set)
  if self.class.validation_set_defined?(set)
    @_validation_set = set.to_sym
  else
    raise ArgumentError, "There is no validation set `#{set}'"
  end
end