Class: CouchRest::Validation::ContextualValidators
- Defined in:
- lib/couchrest/validation/contextual_validators.rb
Overview
Instance Method Summary collapse
-
#clear! ⇒ Object
Clear all named context validators off of the resource.
-
#context(name) ⇒ Array
Return an array of validators for a named context.
-
#contexts ⇒ Hash
Get a hash of named context validators for the resource.
- #dump ⇒ Object
-
#execute(named_context, target) ⇒ Boolean
Execute all validators in the named context against the target.
Instance Method Details
#clear! ⇒ Object
Clear all named context validators off of the resource
55 56 57 |
# File 'lib/couchrest/validation/contextual_validators.rb', line 55 def clear! contexts.clear end |
#context(name) ⇒ Array
Return an array of validators for a named context
49 50 51 |
# File 'lib/couchrest/validation/contextual_validators.rb', line 49 def context(name) contexts[name] ||= [] end |
#contexts ⇒ Hash
Get a hash of named context validators for the resource
42 43 44 |
# File 'lib/couchrest/validation/contextual_validators.rb', line 42 def contexts @contexts ||= {} end |
#dump ⇒ Object
33 34 35 36 37 |
# File 'lib/couchrest/validation/contextual_validators.rb', line 33 def dump contexts.each_pair do |key, context| puts "Key=#{key} Context: #{context}" end end |
#execute(named_context, target) ⇒ Boolean
Execute all validators in the named context against the target
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/couchrest/validation/contextual_validators.rb', line 64 def execute(named_context, target) raise(ArgumentError, 'invalid context specified') if !named_context || (contexts.length > 0 && !contexts[named_context]) target.errors.clear! result = true context(named_context).each do |validator| next unless validator.execute?(target) result = false unless validator.call(target) end result end |