Class: DataMapper::Validate::ContextualValidators

  • Object
    • DataMapper::Validate::ContextualValidators

Public Visibility

Public Instance Method Summary

#clear!

Clear all named context validators off of the resource.

#context(name)

Return an array of validators for a named context.

Returns:

#contexts

Get a hash of named context validators for the resource.

Returns:

#dump
#execute(named_context, target)

Execute all validators in the named context against the target.

Returns:

Public Instance Methods Inherited from Object

validatable?

Public Instance Method Details

clear!

public clear!

Clear all named context validators off of the resource

[View source]


33
34
35
36
37
38
# File 'dm-more/dm-validations/lib/dm-validations/contextual_validators.rb', line 33

def clear!



  contexts.clear
end

context

public context(name)

Return an array of validators for a named context

Meta Tags

Returns:

<Array> An array of validators

[View source]


26
27
28
29
# File 'dm-more/dm-validations/lib/dm-validations/contextual_validators.rb', line 26

def context(name)
  contexts[name] = [] unless contexts.has_key?(name)
  contexts[name]
end

contexts

public contexts

Get a hash of named context validators for the resource

Meta Tags

Returns:

<Hash> a hash of validators <GenericValidator>

[View source]


19
20
21
22
23
24
# File 'dm-more/dm-validations/lib/dm-validations/contextual_validators.rb', line 19

def contexts



  @contexts ||= @contexts = {}
end

dump

public dump
[View source]


10
11
12
13
14
15
16
17
# File 'dm-more/dm-validations/lib/dm-validations/contextual_validators.rb', line 10

def dump



  contexts.each_pair do |key,context|
    puts "Key=#{key} Context: #{context}"
  end
end

execute

public execute(named_context, target)

Execute all validators in the named context against the target

Meta Tags

Parameters:

<Symbol>

named_context the context we are validating against

<Object>

target the resource that we are validating

Returns:

<Boolean> true if all are valid, otherwise false

[View source]


42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'dm-more/dm-validations/lib/dm-validations/contextual_validators.rb', line 42

def execute(named_context, target)
  target.errors.clear!
  result = true
  context(named_context).each do |validator|
    if validator.execute?(target)




      result = false if !validator.call(target)
    end
  end
  return result
end