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

#_runnerObject



54
55
56
# File 'lib/sshkit/custom/dsl/config_statements.rb', line 54

def _runner
  _config_store.runner
end

#_setup_runner(hosts, options) ⇒ Object



49
50
51
52
# File 'lib/sshkit/custom/dsl/config_statements.rb', line 49

def _setup_runner(hosts, options)
  _config_store.backends = hosts
  _config_store.create_runner options
end

#as(who) ⇒ Object



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

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



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

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

  _setup_runner(hosts, options)

  _runner.apply_block_to_bcks(&block) if block_given?
end

#with(environment) ⇒ Object



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

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

#within(directory) ⇒ Object



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

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