Method: LHS::Problems::Nested::Base#nest

Defined in:
lib/lhs/problems/nested/base.rb

#nest(messages, scope = nil) ⇒ Object

Filters base errors by scope and reduces key by given scope name; returns plain array if end of tree is reached



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/lhs/problems/nested/base.rb', line 9

def nest(messages, scope = nil)
  scope = translate_rails_to_api_scope(scope)
  return messages unless scope
  messages = messages.select do |key, _|
    key.match(/^#{scope}/)
  end
  # if only one key and this key has no dots, exit with plain
  if reached_leaf?(messages)
    messages.first[1]
  else
    remove_scope(messages, scope)
  end
end