class CommandList

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

Public Class Methods

new() click to toggle source
# File lib/cuba_genie/command_list.rb, line 5
def initialize
  @commands = []
end

Public Instance Methods

add_command(cmd) click to toggle source
# File lib/cuba_genie/command_list.rb, line 9
def add_command(cmd)
  @commands << cmd
end
description() click to toggle source
# File lib/cuba_genie/command_list.rb, line 32
def description
  description = ''
  @commands.each { |cmd| description += cmd.description + "\n" }
  description
end
execute() click to toggle source
# 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
length() click to toggle source
# File lib/cuba_genie/command_list.rb, line 13
def length
  @commands.size
end
Also aliased as: size

Private Instance Methods

size()
Alias for: length
unexecute(idx) click to toggle source
# File lib/cuba_genie/command_list.rb, line 39
def unexecute(idx)
  @commands.slice(0, idx + 1).reverse_each do |cmd| 
    cmd.rollback_msg
    cmd.unexecute
  end
end