Class: Warden::Proxy::Errors

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/warden/errors.rb

Overview

Lifted from DataMapper's dm-validations plugin :)

Author:

  • Guy van den Berg

Since:

  • DM 0.9

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object

Since:

  • DM 0.9



51
52
53
# File 'lib/warden/errors.rb', line 51

def method_missing(meth, *args, &block)
  errors.send(meth, *args, &block)
end

Instance Method Details

#add(field_name, message) ⇒ Object

Add a authentication error. Use the field_name :general if the errors does not apply to a specific field of the Resource.

Parameters:

  • field_name (Symbol)

    the name of the field that caused the error

  • message (String)

    the message to add

Since:

  • DM 0.9



21
22
23
# File 'lib/warden/errors.rb', line 21

def add(field_name, message)
  (errors[field_name] ||= []) << message
end

#clear!Object

Clear existing authentication errors.

Since:

  • DM 0.9



12
13
14
# File 'lib/warden/errors.rb', line 12

def clear!
  errors.clear
end

#eachObject

Since:

  • DM 0.9



40
41
42
43
44
45
# File 'lib/warden/errors.rb', line 40

def each
  errors.map.each do |k,v|
    next if blank?(v)
    yield(v)
  end
end

#empty?Boolean

Returns:

  • (Boolean)

Since:

  • DM 0.9



47
48
49
# File 'lib/warden/errors.rb', line 47

def empty?
  entries.empty?
end

#full_messagesObject

Collect all errors into a single list.

Since:

  • DM 0.9



26
27
28
29
30
# File 'lib/warden/errors.rb', line 26

def full_messages
  errors.inject([]) do |list,pair|
    list += pair.last
  end
end

#on(field_name) ⇒ Object

Return authentication errors for a particular field_name.

Parameters:

  • field_name (Symbol)

    the name of the field you want an error for

Since:

  • DM 0.9



35
36
37
38
# File 'lib/warden/errors.rb', line 35

def on(field_name)
  errors_for_field = errors[field_name]
  blank?(errors_for_field) ? nil : errors_for_field
end