Class: Reform::Validation::Groups

Inherits:
Array
  • Object
show all
Defined in:
lib/reform/validation/groups.rb

Overview

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

Defined Under Namespace

Classes: Validate

Instance Method Summary collapse

Constructor Details

#initialize(group_class) ⇒ Groups

Returns a new instance of Groups.



11
12
13
# File 'lib/reform/validation/groups.rb', line 11

def initialize(group_class)
  @group_class = group_class
end

Instance Method Details

#add(name, options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# 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