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.



63
64
65
# File 'lib/active_merchant/billing/compatibility.rb', line 63

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

Instance Method Details

#[](key) ⇒ Object



69
70
71
# File 'lib/active_merchant/billing/compatibility.rb', line 69

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

#[]=(key, value) ⇒ Object



73
74
75
# File 'lib/active_merchant/billing/compatibility.rb', line 73

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

#add(field, error) ⇒ Object



85
86
87
# File 'lib/active_merchant/billing/compatibility.rb', line 85

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

#add_to_base(error) ⇒ Object



89
90
91
# File 'lib/active_merchant/billing/compatibility.rb', line 89

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

#each_fullObject



93
94
95
# File 'lib/active_merchant/billing/compatibility.rb', line 93

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

#empty?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/active_merchant/billing/compatibility.rb', line 77

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

#full_messagesObject



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

def full_messages
  result = []

  self.each do |key, messages|
    next unless messages && !messages.empty?

    if key == 'base'
      result << messages.first.to_s
    else
      result << "#{Compatibility.humanize(key)} #{messages.first}"
    end
  end

  result
end

#on(field) ⇒ Object



81
82
83
# File 'lib/active_merchant/billing/compatibility.rb', line 81

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