class Reform::Validation::Groups

Set of Validation::Group objects. This implements adding, iterating, and finding groups, including “inheritance” and insertions.

Public Class Methods

new(group_class) click to toggle source
# File lib/reform/validation/groups.rb, line 11
def initialize(group_class)
  @group_class = group_class
end

Public Instance Methods

add(name, options) click to toggle source
# File lib/reform/validation/groups.rb, line 15
def add(name, options)
  if options[:inherit]
    return self[name] if self[name]
  end

  i = index_for(options)

  self.insert(i, [name, group = @group_class.new(options), options]) # Group.new
  group
end

Private Instance Methods

[](name) click to toggle source
# File lib/reform/validation/groups.rb, line 33
def [](name)
  cfg = find { |c| c.first == name }
  return unless cfg
  cfg[1]
end
index_for(options) click to toggle source
# File lib/reform/validation/groups.rb, line 28
def index_for(options)
  return find_index { |el| el.first == options[:after] } + 1 if options[:after]
  size # default index: append.
end