Module: SSHKit::Custom::DSL::ConfigStatements

Included in:
SSHKit::Custom::DSL
Defined in:
lib/sshkit/custom/dsl/config_statements.rb

Instance Method Summary collapse

Instance Method Details

#as(who) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/sshkit/custom/dsl/config_statements.rb', line 32

def as(who)

  if who.respond_to? :fetch
    user = who.fetch(:user,  who.fetch("user"))
    group = who.fetch(:group, who.fetch("group", nil))
  else
    user = who
    group = nil
  end

  _guard_sudo_user!(user)
  _guard_sudo_group!(user, group)

  _config_store.add_user_group user, group

  yield if block_given?
ensure
  _config_store.pop_user_group
end

#on(hosts, options = {}, &block) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/sshkit/custom/dsl/config_statements.rb', line 6

def on(hosts, options={}, &block)
  hosts = Array(hosts).map { |rh| Host(rh) }.uniq

  _config_store.backends = hosts
  _config_store.create_runner options

  _config_store.runner.apply_block_to_bcks(&block) if block_given?
end

#with(environment) ⇒ Object



25
26
27
28
29
30
# File 'lib/sshkit/custom/dsl/config_statements.rb', line 25

def with(environment)
  _config_store.add_env environment
  yield if block_given?
ensure
  _config_store.pop_env
end

#within(directory) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/sshkit/custom/dsl/config_statements.rb', line 15

def within(directory)
  _guard_dir!(File.join(_config_store.active_backend.pwd + [directory]))

  _config_store.add_pwd directory

  yield if block_given?
ensure
  _config_store.pop_pwd
end