Class Index [+]

Quicksearch

DataMapper::Validations::ClassMethods

Private Class Methods

create_context_instance_methods(model, context) click to toggle source

Given a new context create an instance method of valid_for_? which simply calls valid?(context) if it does not already exist

@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

Public Instance Methods

create(attributes = {}, *args) click to toggle source

@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
inherited(base) click to toggle source

@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
validators() click to toggle source

Return the set of contextual validators or create a new one

@api public

     # File lib/dm-validations.rb, line 112
112:       def validators
113:         @validators ||= ContextualValidators.new(self)
114:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.