Class: ValidationSets::ValidationProxy
- Inherits:
-
Object
- Object
- ValidationSets::ValidationProxy
- Defined in:
- lib/validation_sets/validation_proxy.rb
Overview
A ValidationSet instance is used to add extra options to validations to make sure the only run when a certain validation set is active.
Instance Method Summary collapse
-
#initialize(model, set) ⇒ ValidationProxy
constructor
A new instance of ValidationProxy.
-
#method_missing(method, *args, &block) ⇒ Object
Forwards all other methods (ie. validates_presence_of) to the model class with extra options.
Constructor Details
#initialize(model, set) ⇒ ValidationProxy
Returns a new instance of ValidationProxy.
5 6 7 8 |
# File 'lib/validation_sets/validation_proxy.rb', line 5 def initialize(model, set) @model = model @set = set end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Forwards all other methods (ie. validates_presence_of) to the model class with extra options
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/validation_sets/validation_proxy.rb', line 12 def method_missing(method, *args, &block) = args. [:if] = Array.wrap([:if]) [:if] << "_validation_set == :#{@set}" # BUG: Callbacks get deleted from their chain when they're the same as a previous callback if (method == :validate) and !block and args[0].kind_of?(Symbol) callback = args.shift block = lambda { send(callback) } end args << @model.send(method, *args, &block) end |