Class: Attribool::AttributeList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/attribool/attribute_list.rb

Overview

Enumerable class that generates a list of attributes from a list of strings or symbols.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*attributes) ⇒ AttributeList

Construct the list.

Parameters:

  • *attributes (String, Symbol)


26
27
28
29
# File 'lib/attribool/attribute_list.rb', line 26

def initialize(*attributes)
  ValidatorService.call(:attribute_list, *attributes)
  @entries = attributes
end

Class Method Details

.build(*attribute_names, method_name: nil) ⇒ AttributeList

Create an AttributeList from a list of attribute names.

Parameters:

  • *attribute_names (String, Symbol)

Returns:



18
19
20
# File 'lib/attribool/attribute_list.rb', line 18

def self.build(*attribute_names, method_name: nil)
  new(*attribute_names.map { |a| Attribool::Attribute.new(a, method_name) })
end

Instance Method Details

#each(&block) ⇒ Enumerable

Yield every entry in the list to a block.

Parameters:

  • &block (block)

Returns:

  • (Enumerable)


37
38
39
# File 'lib/attribool/attribute_list.rb', line 37

def each(&block)
  @entries.each(&block)
end