Given a new context create an instance method of valid_for_
@api private
# File lib/dm-validations.rb, line 141 141: def self.create_context_instance_methods(model, context) 142: # TODO: deprecate `valid_for_#{context}?` 143: # what's wrong with requiring the caller to pass the context as an arg? 144: # eg, `valid?(:context)` 145: # these methods are handy for symbol-based callbacks, 146: # eg. `:if => :valid_for_context?` 147: # but these methods are so trivial to add where needed, making it 148: # overkill to do this for all contexts on all validated objects. 149: context = context.to_sym 150: 151: name = "valid_for_#{context}?" 152: present = model.respond_to?(:resource_method_defined) ? model.resource_method_defined?(name) : model.instance_methods.include?(name) 153: unless present 154: model.class_eval def #{name} # def valid_for_signup? valid?(#{context.inspect}) # valid?(:signup) end # end, __FILE__, __LINE__ + 1 155: end 156: end
@api public
# File lib/dm-validations.rb, line 128 128: def create(attributes = {}, *args) 129: resource = new(attributes) 130: resource.save(*args) 131: resource 132: end
@api private
# File lib/dm-validations.rb, line 117 117: def inherited(base) 118: super 119: self.validators.contexts.each do |context, validators| 120: validators.each do |v| 121: options = v.options.merge(:context => context) 122: base.validators.add(v.class, v.field_name, options) 123: end 124: end 125: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.