Class: Rapporteur::CheckList

Inherits:
Object
  • Object
show all
Defined in:
lib/rapporteur/check_list.rb

Overview

Manages a list of checks.

The goals of this object are to store and return the check objects given to it in the same order they were given (in Ruby 1.8 and newer). And, to ensure that the same check is not added twice to be run.

Previously, a native Ruby Set was used. However, Sets do not guarantee order, particularly in Ruby 1.8. A simple Array is possible, but loses the uniqueness constraint of the objects added.

Instance Method Summary collapse

Constructor Details

#initializeCheckList

Public: Returns a new, empty CheckList instance.



15
16
17
# File 'lib/rapporteur/check_list.rb', line 15

def initialize
  @list = Array.new
end

Instance Method Details

#add(check) ⇒ Object

Public: Add a new check to the list.

Returns the CheckList instance.



24
25
26
27
# File 'lib/rapporteur/check_list.rb', line 24

def add(check)
  @list << check unless @list.include?(check)
  self
end

#clearObject

Public: Empties all checks from the list. This functionally resets the list to an initial state.

Returns the CheckList instance.



34
35
36
37
# File 'lib/rapporteur/check_list.rb', line 34

def clear
  @list.clear
  self
end

#each(&block) ⇒ Object

Public: Iterates over all of the contained objects and yields them out, individually.

Returns the CheckList instance.



44
45
46
47
# File 'lib/rapporteur/check_list.rb', line 44

def each(&block)
  @list.each(&block)
  self
end

#empty?Boolean

Public: Returns true if the list is empty.

Returns:

  • (Boolean)


51
52
53
# File 'lib/rapporteur/check_list.rb', line 51

def empty?
  @list.empty?
end

#to_aObject

Public: Returns the objects in the list in an Array.



57
58
59
# File 'lib/rapporteur/check_list.rb', line 57

def to_a
  @list.dup
end