Module: CapUtil

Included in:
BundlerCmd, GitBranch, ServerRoles, ServerRolesYaml, SharedPath
Defined in:
lib/cap-util.rb,
lib/cap-util/run.rb,
lib/cap-util/say.rb,
lib/cap-util/halt.rb,
lib/cap-util/time.rb,
lib/cap-util/timer.rb,
lib/cap-util/version.rb,
lib/cap-util/fake_cap.rb,
lib/cap-util/unset_var.rb,
lib/cap-util/git_branch.rb,
lib/cap-util/bundler_cmd.rb,
lib/cap-util/shared_path.rb,
lib/cap-util/server_roles.rb,
lib/cap-util/local_cmd_runner.rb,
lib/cap-util/server_roles_yaml.rb

Defined Under Namespace

Modules: Halt, Run, Say, Time, UnsetVar Classes: BundlerCmd, FakeCap, GitBranch, Halted, LocalCmdRunner, ServerRoles, ServerRolesYaml, SharedPath, Timer

Constant Summary collapse

VERSION =
"1.5.2"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.color(*args) ⇒ Object



5
6
7
# File 'lib/cap-util/say.rb', line 5

def self.color(*args)
  Capistrano::CLI.ui.color(*args)
end

.halt(msg = 'halted') ⇒ Object

Raises:



7
8
9
# File 'lib/cap-util/halt.rb', line 7

def self.halt(msg = 'halted')
  raise CapUtil::Halted, color(msg, :bold, :yellow)
end

.included(receiver) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/cap-util.rb', line 10

def self.included(receiver)
  receiver.send(:attr_accessor, :cap)

  receiver.send(:include, CapUtil::Say)
  receiver.send(:include, CapUtil::Halt)
  receiver.send(:include, CapUtil::Run)
  receiver.send(:include, CapUtil::Time)
end

.run_locally(cmd_str) ⇒ Object



5
6
7
# File 'lib/cap-util/run.rb', line 5

def self.run_locally(cmd_str)
  LocalCmdRunner.new(cmd_str).run!
end

.run_locally_with_stdin(cmd_str, input) ⇒ Object



9
10
11
# File 'lib/cap-util/run.rb', line 9

def self.run_locally_with_stdin(cmd_str, input)
  LocalCmdRunner.new(cmd_str).run!(input)
end

.say(msg, *args) ⇒ Object



9
10
11
# File 'lib/cap-util/say.rb', line 9

def self.say(msg, *args)
  say_raw("    #{msg}", *args)
end

.say_bulleted(msg, *args) ⇒ Object



13
14
15
# File 'lib/cap-util/say.rb', line 13

def self.say_bulleted(msg, *args)
  say_raw("  * #{msg}", *args)
end

.say_error(msg, *args) ⇒ Object



17
18
19
# File 'lib/cap-util/say.rb', line 17

def self.say_error(msg, *args)
  say("#{color "[ERROR]", :bold, :red} #{msg}", *args)
end

.say_raw(msg, *args) ⇒ Object



25
26
27
# File 'lib/cap-util/say.rb', line 25

def self.say_raw(msg, *args)
  Capistrano::CLI.ui.say(msg, *args) if !ENV['CAPUTIL_SILENCE_SAY']
end

.say_warning(msg, *args) ⇒ Object



21
22
23
# File 'lib/cap-util/say.rb', line 21

def self.say_warning(msg, *args)
  say("#{color "[WARN]", :bold, :yellow} #{msg}", *args)
end

.time(timer_set, name, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/cap-util/time.rb', line 5

def self.time(timer_set, name, &block)
  timer_set[name] ||= CapUtil::Timer.new(name)
  if !block.nil?
    begin
      timer_set[name].start
      block.call
    ensure
      timer_set[name].end
    end
  end
  timer_set[name]
end

Instance Method Details

#get(*args, &block) ⇒ Object



19
20
21
# File 'lib/cap-util.rb', line 19

def get(*args, &block)
  cap.get(*args, &block)
end

#hostnameObject



23
24
25
26
27
# File 'lib/cap-util.rb', line 23

def hostname
  val = ""
  run("hostname") {|ch, stream, out| val = out.strip}
  val
end