module SSHKit::Custom::Config::Store
Public Instance Methods
@api private
# File lib/sshkit/custom/config/store.rb, line 63 def _envs config_scope[:_envs] ||= [] end
@api private
# File lib/sshkit/custom/config/store.rb, line 83 def _user_groups config_scope[:_user_groups] ||= [] end
Returns the active backend in the current thread
# File lib/sshkit/custom/config/store.rb, line 104 def active_backend SSHKit::Custom::Runner::Abstract.active_backend end
Set the environment for the current backend. @param env [Hash<String, String>] The new ENV-Vars to be used.
# 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
Set the working directory for the current backend. @param directory [String] The new working directory
# File lib/sshkit/custom/config/store.rb, line 51 def add_pwd(directory) active_backend.pwd ||= [] active_backend.pwd << directory end
Set the user and group for the current backend. @param user [String] The new username @param group [String, nil] The new group
# 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
Get the actual backends
# File lib/sshkit/custom/config/store.rb, line 45 def backends @backends ||= [] end
Sets the actual backends
# File lib/sshkit/custom/config/store.rb, line 40 def backends=(hosts) @backends = hosts.map { |host| SSHKit.config.backend.new(host) } end
@api private
# File lib/sshkit/custom/config/store.rb, line 13 def config_scope @config_scope ||= ScopedStorage::Scope.new('sshkit_dsl_config', scope_storage) end
Creates a new runner @option opts [Symbol] :in Chooses the runner to be used
:parallel => Parallel :sequence => Sequential :groups => Group
@option opts [Integer] :wait Amount of seconds to sleep between executions for Sequential and Parallel Runner
@option opts [Integer] :limit Amount of hosts to use in one Batch for Group Runner
# 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
Sets the default runner opts for instance change the default runner
# File lib/sshkit/custom/config/store.rb, line 109 def default_runner_opts(opts) global_config_scope[:_default_runner_opts] = opts end
@api private
# File lib/sshkit/custom/config/store.rb, line 18 def global_config_scope @global_config_scope ||= ScopedStorage::Scope.new('sshkit_dsl_global_config', ScopedStorage::ThreadGlobalStorage) end
Resets the environment variables to the previous one.
# File lib/sshkit/custom/config/store.rb, line 77 def pop_env old_env = _envs.pop || {} active_backend.env = old_env end
Set the working directory to the previous working directory for the current backend.
# File lib/sshkit/custom/config/store.rb, line 57 def pop_pwd active_backend.pwd ||= [] active_backend.pwd.pop end
Resets user and group to the previous one.
# 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
The actual runner object
# File lib/sshkit/custom/config/store.rb, line 35 def runner @runner.tap { |r| r.backends = backends } end
@api private
# File lib/sshkit/custom/config/store.rb, line 8 def scope_storage ScopedStorage::ThreadLocalStorage end