Class: Mina::Commands

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Mina::Configuration::DSL, Helpers::Internal
Defined in:
lib/mina/commands.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mina::Configuration::DSL

included

Methods included from Helpers::Internal

#deploy_script, #echo_cmd, #erb, #error!, #indent, #next_version, #report_time, #unindent

Methods included from Helpers::Output

#color, #print_command, #print_error, #print_info, #print_line, #print_status, #print_stderr, #print_stdout

Constructor Details

#initialize(stage = :default) ⇒ Commands

Returns a new instance of Commands


10
11
12
13
# File 'lib/mina/commands.rb', line 10

def initialize(stage = :default)
  @stage = stage
  @queue = Hash.new { |hash, key| hash[key] = [] }
end

Instance Attribute Details

#queueObject (readonly)

Returns the value of attribute queue


7
8
9
# File 'lib/mina/commands.rb', line 7

def queue
  @queue
end

#stageObject

Returns the value of attribute stage


8
9
10
# File 'lib/mina/commands.rb', line 8

def stage
  @stage
end

Instance Method Details

#command(code, strip: true, quiet: false, indent: nil) ⇒ Object


15
16
17
18
19
# File 'lib/mina/commands.rb', line 15

def command(code, strip: true, quiet: false, indent: nil)
  code = unindent(code) if strip
  code = indent(indent, code) if indent
  queue[stage] << (quiet ? code : echo_cmd(code))
end

#comment(code, indent: nil) ⇒ Object


21
22
23
24
25
26
27
# File 'lib/mina/commands.rb', line 21

def comment(code, indent: nil)
  if indent
    queue[stage] << indent(indent, %{echo "-----> #{code}"})
  else
    queue[stage] << %{echo "-----> #{code}"}
  end
end

#delete(stage) ⇒ Object


29
30
31
# File 'lib/mina/commands.rb', line 29

def delete(stage)
  queue.delete(stage) || []
end

#process(path = nil) ⇒ Object


33
34
35
36
37
38
39
40
# File 'lib/mina/commands.rb', line 33

def process(path = nil)
  if path
    queue[stage].unshift(%{echo "$ cd #{path}"}) if fetch(:verbose)
    %{(cd #{path} && #{queue[stage].join(' && ')} && cd -)}
  else
    queue[stage].join("\n")
  end
end

#run(backend) ⇒ Object


42
43
44
45
46
47
48
# File 'lib/mina/commands.rb', line 42

def run(backend)
  return if queue.empty?
  report_time do
    status = Mina::Runner.new(process, backend).run
    error! 'Run Error' unless status
  end
end