Class: Rbcli::Scriptwrapper
- Inherits:
-
Object
- Object
- Rbcli::Scriptwrapper
- Defined in:
- lib/rbcli/scriptwrapping/scriptwrapper.rb
Instance Method Summary collapse
- #execute(params, args, global_opts, config) ⇒ Object
-
#initialize(path, envvars = nil, block = nil) ⇒ Scriptwrapper
constructor
A new instance of Scriptwrapper.
Constructor Details
#initialize(path, envvars = nil, block = nil) ⇒ Scriptwrapper
Returns a new instance of Scriptwrapper.
39 40 41 42 43 |
# File 'lib/rbcli/scriptwrapping/scriptwrapper.rb', line 39 def initialize path, envvars = nil, block = nil @path = path @envvars = envvars || {} @block = block end |
Instance Method Details
#execute(params, args, global_opts, config) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rbcli/scriptwrapping/scriptwrapper.rb', line 45 def execute params, args, global_opts, config #### #### The following code will flatten one level of the hashes into separate variables #### It is deprecated in favor of passing along json to be parsed with JQ #### # 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 env_hash = { '__RBCLI_PARAMS' => params.to_json, '__RBCLI_ARGS' => args.to_json, '__RBCLI_GLOBAL' => global_opts.to_json, '__RBCLI_CONFIG' => config.to_json, '__RBCLI_MYVARS' => @envvars.to_json } path = @block.call params, args, global_opts, config system(env_hash, path) else system(@envvars, @path) end # IO.popen(env_hash, path) do |io| # while (line = io.gets) do # puts line # end # end end |