Module: SSHKit::Custom::Config::Store

Defined in:
lib/sshkit/custom/config/store.rb

Class Method Summary collapse

Class Method Details

.active_backendObject

Returns the active backend in the current thread



104
105
106
# File 'lib/sshkit/custom/config/store.rb', line 104

def active_backend
  SSHKit::Custom::Runner::Abstract.active_backend
end

.add_env(env) ⇒ Object

Set the environment for the current backend.

Parameters:

  • env (Hash<String, String>)

    The new ENV-Vars to be used.



69
70
71
72
73
74
# File 'lib/sshkit/custom/config/store.rb', line 69

def add_env(env)
  old_env = active_backend.env.clone
  _envs << old_env
  env = old_env.merge(env)
  active_backend.env = env
end

.add_pwd(directory) ⇒ Object

Set the working directory for the current backend.

Parameters:

  • directory (String)

    The new working directory



51
52
53
54
# File 'lib/sshkit/custom/config/store.rb', line 51

def add_pwd(directory)
  active_backend.pwd ||= []
  active_backend.pwd << directory
end

.add_user_group(user, group) ⇒ Object

Set the user and group for the current backend.

Parameters:

  • user (String)

    The new username

  • group (String, nil)

    The new group



90
91
92
93
94
# File 'lib/sshkit/custom/config/store.rb', line 90

def add_user_group(user, group)
  _user_groups << { user: active_backend.user, group: active_backend.group }
  active_backend.user = user
  active_backend.group = group
end

.backendsObject

Get the actual backends



45
46
47
# File 'lib/sshkit/custom/config/store.rb', line 45

def backends
  @backends ||= []
end

.backends=(hosts) ⇒ Object

Sets the actual backends



40
41
42
# File 'lib/sshkit/custom/config/store.rb', line 40

def backends=(hosts)
  @backends = hosts.map { |host| SSHKit.config.backend.new(host) }
end

.create_runner(opts) ⇒ Object

Creates a new runner

Parameters:

  • opts (Hash)

    a customizable set of options

Options Hash (opts):

  • :in (Symbol)

    Chooses the runner to be used :parallel => Parallel :sequence => Sequential :groups => Group

  • :wait (Integer)

    Amount of seconds to sleep between executions for Sequential and Parallel Runner

  • :limit (Integer)

    Amount of hosts to use in one Batch for Group Runner



30
31
32
# File 'lib/sshkit/custom/config/store.rb', line 30

def create_runner(opts)
  @runner = Runner::Abstract.create_runner((global_config_scope[:_default_runner_opts] || {}).merge(opts))
end

.default_runner_opts(opts) ⇒ Object

Sets the default runner opts for instance change the default runner



109
110
111
# File 'lib/sshkit/custom/config/store.rb', line 109

def default_runner_opts(opts)
  global_config_scope[:_default_runner_opts] = opts
end

.pop_envObject

Resets the environment variables to the previous one.



77
78
79
80
# File 'lib/sshkit/custom/config/store.rb', line 77

def pop_env
  old_env = _envs.pop || {}
  active_backend.env = old_env
end

.pop_pwdObject

Set the working directory to the previous working directory for the current backend.



57
58
59
60
# File 'lib/sshkit/custom/config/store.rb', line 57

def pop_pwd
  active_backend.pwd ||= []
  active_backend.pwd.pop
end

.pop_user_groupObject

Resets user and group to the previous one.



97
98
99
100
101
# File 'lib/sshkit/custom/config/store.rb', line 97

def pop_user_group
  old_user_group = _user_groups.pop || {}
  active_backend.user = old_user_group[:user]
  active_backend.group = old_user_group[:group]
end

.runnerObject

The actual runner object



35
36
37
# File 'lib/sshkit/custom/config/store.rb', line 35

def runner
  @runner.tap { |r| r.backends = backends }
end