Class: ActiveMerchant::Billing::Rails::Model::Errors

Inherits:
Hash
  • Object
show all
Defined in:
lib/active_merchant/billing/compatibility.rb

Instance Method Summary collapse

Constructor Details

#initializeErrors

Returns a new instance of Errors.



65
66
67
# File 'lib/active_merchant/billing/compatibility.rb', line 65

def initialize
  super(){|h, k| h[k] = []}
end

Instance Method Details

#[](key) ⇒ Object



71
72
73
# File 'lib/active_merchant/billing/compatibility.rb', line 71

def [](key)
  super(key.to_s)
end

#[]=(key, value) ⇒ Object



75
76
77
# File 'lib/active_merchant/billing/compatibility.rb', line 75

def []=(key, value)
  super(key.to_s, value)
end

#add(field, error) ⇒ Object



87
88
89
# File 'lib/active_merchant/billing/compatibility.rb', line 87

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

#add_to_base(error) ⇒ Object



91
92
93
# File 'lib/active_merchant/billing/compatibility.rb', line 91

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

#each_fullObject



95
96
97
# File 'lib/active_merchant/billing/compatibility.rb', line 95

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

#empty?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/active_merchant/billing/compatibility.rb', line 79

def empty?
  all?{|k, v| v && v.empty?}
end

#full_messagesObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/active_merchant/billing/compatibility.rb', line 99

def full_messages
  result = []

  self.each do |key, messages|
    next unless(messages && !messages.empty?)
    if key == 'base'
      result << "#{messages.first}"
    else
      result << "#{Compatibility.humanize(key)} #{messages.first}"
    end
  end

  result
end

#on(field) ⇒ Object



83
84
85
# File 'lib/active_merchant/billing/compatibility.rb', line 83

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