Class: EpubForge::Action::CliSequence

Inherits:
Object
  • Object
show all
Defined in:
lib/epubforge/action/cli_sequence.rb

Instance Method Summary collapse

Constructor Details

#initializeCliSequence

Returns a new instance of CliSequence.



4
5
6
7
8
9
# File 'lib/epubforge/action/cli_sequence.rb', line 4

def initialize
  @defaults = {}
  @local_dir
  @commands = []
  @completed = []
end

Instance Method Details

#add_command(command, undo = "", opts = {}) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/epubforge/action/cli_sequence.rb', line 46

def add_command( command, undo = "", opts = {} )
  for default, setting in @defaults
    opts[default] ||= setting
  end
  
  @commands.push( CliCommand.new(command, undo, opts) )
end

#add_local_command(command, undo = nil, opts = {}) ⇒ Object



19
20
21
# File 'lib/epubforge/action/cli_sequence.rb', line 19

def add_local_command( command, undo = nil, opts = {} )
  add_command( command, undo, opts )
end

#add_remote_command(command, undo = nil, opts = {}) ⇒ Object



23
24
25
26
# File 'lib/epubforge/action/cli_sequence.rb', line 23

def add_remote_command( command, undo = nil, opts = {} )
  opts[:remote] ||= @remote         # the default username/host can be overridden by sending a different opts[:remote]
  add_command( command, undo, opts)
end

#default(k, v) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/epubforge/action/cli_sequence.rb', line 11

def default( k, v )
  if k == :remote
    @remote = v
  else
    @defaults[k] = v
  end
end

#executeObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/epubforge/action/cli_sequence.rb', line 28

def execute
  @failed = false
  while (cmd = @commands.shift) && (@failed == false)
    @failed = true unless cmd.execute.success?
    @completed.push( cmd )
  end
  
  undo unless @failed == false
  !@failed
end

#undoObject



39
40
41
42
43
44
# File 'lib/epubforge/action/cli_sequence.rb', line 39

def undo
  while cmd = @completed.pop
    result = cmd.undo
    @commands.unshift( cmd )
  end
end