Class: Rbcli::Scriptwrapper
- Inherits:
-
Object
- Object
- Rbcli::Scriptwrapper
- Defined in:
- lib/rbcli/features/scriptwrapper.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #execute(params, args, global_opts, config) ⇒ Object
-
#initialize(path, envvars = nil, block = nil, script = false) ⇒ Scriptwrapper
constructor
A new instance of Scriptwrapper.
Constructor Details
#initialize(path, envvars = nil, block = nil, script = false) ⇒ Scriptwrapper
Returns a new instance of Scriptwrapper.
23 24 25 26 27 28 |
# File 'lib/rbcli/features/scriptwrapper.rb', line 23 def initialize path, envvars = nil, block = nil, script = false @path = path @envvars = envvars || {} @block = block @script = script end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
30 31 32 |
# File 'lib/rbcli/features/scriptwrapper.rb', line 30 def path @path end |
Instance Method Details
#execute(params, args, global_opts, config) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 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 |
# File 'lib/rbcli/features/scriptwrapper.rb', line 32 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 || @script 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 } if @block path = @block.call params, args, global_opts, config else path = @path end system(env_hash, path) else system(@envvars.collect{|k,v| [k.to_s, v]}.to_h, @path) end # IO.popen(env_hash, path) do |io| # while (line = io.gets) do # puts line # end # end end |