Module: ValidationSets
- Included in:
- ActiveRecord::Base
- Defined in:
- lib/validation_sets.rb,
lib/validation_sets.rb,
lib/validation_sets.rb,
lib/validation_sets/validation_set.rb,
lib/validation_sets/validation_proxy.rb
Defined Under Namespace
Modules: InstanceMethods Classes: ValidationProxy, ValidationSet
Instance Attribute Summary collapse
-
#current_validation_set ⇒ Object
Used to set the current validation set during definition of the model.
Instance Method Summary collapse
-
#validation_method(on) ⇒ Object
Returns the name of the validation callback method for a save method.
-
#validation_set_defined?(set) ⇒ Boolean
Returns true if the validation set is defined on this class.
-
#validation_set_for(label, &block) ⇒ Object
Add a validation set to the model.
-
#validation_set_method(on, label) ⇒ Object
Returns the name of the validation callback method for a save method and the label of a validation set.
Instance Attribute Details
#current_validation_set ⇒ Object
Used to set the current validation set during definition of the model
52 53 54 |
# File 'lib/validation_sets.rb', line 52 def current_validation_set @current_validation_set end |
Instance Method Details
#validation_method(on) ⇒ Object
Returns the name of the validation callback method for a save method.
65 66 67 68 69 70 71 |
# File 'lib/validation_sets.rb', line 65 def validation_method(on) if current_validation_set validation_set_method(on, current_validation_set) else super end end |
#validation_set_defined?(set) ⇒ Boolean
Returns true if the validation set is defined on this class
43 44 45 |
# File 'lib/validation_sets.rb', line 43 def validation_set_defined?(set) @_validation_sets.include?(set) end |
#validation_set_for(label, &block) ⇒ Object
Add a validation set to the model.
class Account < ActiveRecord::Base
validation_set_for(:activation) do |set|
set.validates_presence_of :username
end
end
36 37 38 39 40 |
# File 'lib/validation_sets.rb', line 36 def validation_set_for(set, &block) @_validation_sets ||= Set.new @_validation_sets << set yield ValidationProxy.new(self, set) end |
#validation_set_method(on, label) ⇒ Object
Returns the name of the validation callback method for a save method and the label of a validation set.
56 57 58 59 60 61 62 |
# File 'lib/validation_sets.rb', line 56 def validation_set_method(on, label) case on when :save then "validate_#{label}_set".to_sym when :create then "validate_on_create_#{label}_set".to_sym when :update then "validate_on_update_#{label}_set".to_sym end end |