Eno::Section » #list

list(name) → array
list(name, options) → array
list(name, loader_proc, options) → array
list(name, options) { |name, value| loader_block } → array

Retrieve the items of a list, optionally supplying a loader block or Proc and options.

enocolors:
- pink
- peach

textures:
-
rubydocument = Eno.parse(input)

document.list('colors')  #=> [ 'pink', 'peach' ]
document.list('sounds')  #=> []

document.list('textures')                         # raises an error
document.list('textures', enforce_values: false)  #=> [ nil ]

document.list('sounds', required: true)         # raises an error
document.list('sounds', enforce_element: true)  # raises an error

document.list('colors') { |name, value| value.upcase }  #=> [ 'PINK', 'PEACH' ]

document.list('colors') do |name, value|
  raise 'Peach may not be on the list!' if value == 'peach'  # raises an error
  return "I like #{value}"
end

document.list('colors', with_elements: true)
  #=> [[ #<Eno::Field value="pink">, 'pink' ],
  #    [ #<Eno::Field value="peach">, 'peach' ]]
  
document.list('colors', min_count: 3)  # raises an error

Parameters

name

The name of the list to return as a string.

loader_block or loader_proc

A block or Proc returning the transformed/validated value or raising anerror. (The block or Proc is applied to each list item on its own, itsargument signature is dynamic, you can either use |value| or |name, value|)

options

enforce_element

Whether the list must be present in the document (defaults to false)

enforce_values

Whether empty list items (- in the document, mapping to nil) are disallowed (defaults to true)

exact_count

Validate that there are exactly n items in the list (takes a number, defaults to nil)

min_count

Validate that there are at least n items in the list (takes a number, defaults to nil)

max_count

Validate that there are at most n items in the list (takes a number, defaults to nil)

required

Alias for enforce_element (this exists on many methods and depending on context refers to either element or value)

with_elements

Whether to return an array of arrays of the form [element, value] instead of just the values (defaults to false)

Return value

The (optionally transformed/validated) values of the items of this list as an array.With with_elements set to true it returns an array of arrays of the form [element, value] instead.