Top Level Namespace

Defined Under Namespace

Modules: ActionController, ActionMailer, ActionView, ActiveRecord, Shoulda, Useful Classes: Array, Date, FalseClass, Hash, Integer, NilClass, Numeric, Object, String, TrueClass

Instance Method Summary collapse

Instance Method Details

#hostnameObject



34
35
36
37
38
39
40
# File 'lib/useful/cap_tasks/globals.rb', line 34

def hostname
  val = ""
  run "hostname" do |ch, stream, out|
    val = out
  end
  val.strip
end

#log(msg, opts = {}) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/useful/cap_tasks/globals.rb', line 18

def log(msg, opts = {})
  if opts[:force]
    puts " ** #{msg}"
  else
    logger.info(msg)
  end
end

#run_locally(cmd) ⇒ Object



12
13
14
15
16
# File 'lib/useful/cap_tasks/globals.rb', line 12

def run_locally(cmd)
  log cmd
  resp = `#{cmd}` rescue nil
  log resp
end

#run_with_password(cmd, options = {}) ⇒ Object



1
2
3
4
5
6
7
8
9
10
# File 'lib/useful/cap_tasks/globals.rb', line 1

def run_with_password(cmd, options={})
  prompt = options.delete(:prompt) || 'Password: '
  password = options.delete(:password)
  log (options.delete(:confirmation) || "Running: '#{cmd}'")
  password ||= Capistrano::CLI.password_prompt(prompt)
  run cmd, options do |ch, stream, out|
    ch.send_data(password+"\n")
  end
  password
end

#total_time_in_values(total_time) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/useful/cap_tasks/globals.rb', line 26

def total_time_in_values(total_time)
  total_time = total_time.round
  values = Hash.new
  values[:minutes] = (total_time) / (60)
  values[:seconds] = total_time - values[:minutes]*60
  values
end