Class: ActiveMerchant::Validateable::Errors

Inherits:
HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/active_merchant/common/validateable.rb

Overview

This hash keeps the errors of the object

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ Errors

Returns a new instance of Errors.



33
34
35
# File 'lib/active_merchant/common/validateable.rb', line 33

def initialize(base)
  @base = base
end

Instance Method Details

#add(field, error) ⇒ Object



48
49
50
51
# File 'lib/active_merchant/common/validateable.rb', line 48

def add(field, error)
  self[field] ||= []
  self[field] << error
end

#add_to_base(error) ⇒ Object



53
54
55
# File 'lib/active_merchant/common/validateable.rb', line 53

def add_to_base(error)
  add(:base, error)
end

#countObject



37
38
39
# File 'lib/active_merchant/common/validateable.rb', line 37

def count
  size
end

#each_fullObject



57
58
59
# File 'lib/active_merchant/common/validateable.rb', line 57

def each_full
  full_messages.each { |msg| yield msg }      
end

#full_messagesObject



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/active_merchant/common/validateable.rb', line 61

def full_messages
  result = []

  self.each do |key, messages| 
    if key == 'base'
      result << "#{messages.first}"
    else
      result << "#{key.to_s.humanize} #{messages.first}"
    end
  end

  result
end

#on(field) ⇒ Object

returns a specific fields error message. if more than one error is available we will only return the first. If no error is available we return an empty string



44
45
46
# File 'lib/active_merchant/common/validateable.rb', line 44

def on(field)
  self[field].to_a.first
end