Class: Rbcli::Scriptwrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/rbcli/scriptwrapping/scriptwrapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, envvars = nil, block = nil) ⇒ Scriptwrapper

Returns a new instance of Scriptwrapper.



15
16
17
18
19
# File 'lib/rbcli/scriptwrapping/scriptwrapper.rb', line 15

def initialize path, envvars = nil, block = nil
	@path = path
	@envvars = envvars
	@block = block
end

Instance Method Details

#execute(params, args, global_opts, config) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rbcli/scriptwrapping/scriptwrapper.rb', line 21

def execute params, args, global_opts, config
	env_hash = {}
	{
			'__PARAMS' => params,
			'__ARGS' => args,
			'__GLOBAL' => global_opts,
			'__CONFIG' => config
	}.each do |name, hsh|
		hsh.each do |k, v|
			env_hash["#{name}_#{k.upcase}"] = v.to_json
		end
	end

	env_hash.merge!(@envvars.deep_stringify!) unless @envvars.nil?

	if @block
		path = @block.call params, args, global_opts, config
	else
		path = @path
	end

	system(env_hash, path)
end