Exception: Config::Validation::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/config/validation/error.rb

Class Method Summary collapse

Class Method Details

.flatten_hash(h, acc = {}, pref = []) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/config/validation/error.rb', line 11

def self.flatten_hash(h, acc={}, pref=[])
  h.inject(acc) do |a, (k, v)|
    if v.is_a?(Hash)
      flatten_hash(v, acc, pref + [k])
    else
      acc[(pref + [k]).join('.')] = v
      acc
    end
  end
end

.format(v_res) ⇒ Object



5
6
7
8
9
# File 'lib/config/validation/error.rb', line 5

def self.format(v_res)
  flatten_hash(v_res.messages).map do |field, msgs|
    "#{' ' * 2}#{field}: #{msgs.join('; ')}"
  end.join('\n')
end