Module: Mina::Helpers::Internal

Includes:
Output
Included in:
Commands, Configuration
Defined in:
lib/mina/helpers/internal.rb

Instance Method Summary collapse

Methods included from Output

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

Instance Method Details

#deploy_scriptObject


6
7
8
9
# File 'lib/mina/helpers/internal.rb', line 6

def deploy_script
  yield
  erb Mina.root_path(fetch(:deploy_script))
end

#echo_cmd(code, ignore_verbose = false) ⇒ Object


17
18
19
20
21
22
23
# File 'lib/mina/helpers/internal.rb', line 17

def echo_cmd(code, ignore_verbose = false)
  if fetch(:verbose) && !ignore_verbose
    "echo #{Shellwords.escape('$ ' + code)} &&\n#{code}"
  else
    code
  end
end

#erb(file, b = binding) ⇒ Object


11
12
13
14
15
# File 'lib/mina/helpers/internal.rb', line 11

def erb(file, b = binding)
  require 'erb'
  erb = ERB.new(File.read(file))
  erb.result b
end

#error!(message) ⇒ Object


55
56
57
58
# File 'lib/mina/helpers/internal.rb', line 55

def error!(message)
  print_error message
  exit 1
end

#indent(count, str) ⇒ Object


25
26
27
# File 'lib/mina/helpers/internal.rb', line 25

def indent(count, str)
  str.gsub(/^/, ' ' * count)
end

#next_versionObject


44
45
46
47
48
49
50
51
52
53
# File 'lib/mina/helpers/internal.rb', line 44

def next_version
  case fetch(:version_scheme)
  when :datetime
    Time.now.utc.strftime("%Y%m%d%H%M%S")
  when :sequence
    "$((`ls -1 #{fetch(:releases_path)} | sort -n | tail -n 1`+1))"
  else
    error! 'Unrecognizes version scheme. Use :datetime or :sequence'
  end
end

#report_timeObject


37
38
39
40
41
42
# File 'lib/mina/helpers/internal.rb', line 37

def report_time
  time_start = Time.now
  output = yield
  print_info "Elapsed time: %.2f seconds" % [Time.now - time_start]
  output
end

#unindent(code) ⇒ Object


29
30
31
32
33
34
35
# File 'lib/mina/helpers/internal.rb', line 29

def unindent(code)
  if code =~ /^\n([ \t]+)/
    code = code.gsub(/^#{$1}/, '')
  end

  code.strip
end