Class: CommandList

Inherits:
Object
  • Object
show all
Defined in:
lib/cuba_genie/command_list.rb

Overview

Implements the Command pattern. Responsible for executing a command list and invoking rollback on any errors

Instance Method Summary collapse

Constructor Details

#initializeCommandList

Returns a new instance of CommandList.



5
6
7
# File 'lib/cuba_genie/command_list.rb', line 5

def initialize
  @commands = []
end

Instance Method Details

#add_command(cmd) ⇒ Object



9
10
11
# File 'lib/cuba_genie/command_list.rb', line 9

def add_command(cmd)
  @commands << cmd
end

#descriptionObject



32
33
34
35
36
# File 'lib/cuba_genie/command_list.rb', line 32

def description
  description = ''
  @commands.each { |cmd| description += cmd.description + "\n" }
  description
end

#executeObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cuba_genie/command_list.rb', line 17

def execute
  res = true
  @commands.each_with_index do |cmd, idx|
    unless cmd.execute
      puts "ERROR: #{cmd.error}"
      unexecute(idx)
      res = false
      break
    end
    puts cmd.description unless ENV['RACK_ENV'] == 'test'
  end
  res
end

#lengthObject Also known as: size



13
14
15
# File 'lib/cuba_genie/command_list.rb', line 13

def length
  @commands.size
end