Class: Constant::Controls::Script::Example

Inherits:
Object
  • Object
show all
Includes:
Initializer
Defined in:
lib/constant/controls/script.rb

Instance Method Summary collapse

Instance Method Details

#errorObject



85
86
87
88
89
90
91
92
93
# File 'lib/constant/controls/script.rb', line 85

def error
  _, error_output, status = execute

  if status.success?
    raise "Script succeeded\n\n#{source}"
  end

  error_output
end

#executeObject



95
96
97
98
99
100
101
102
103
# File 'lib/constant/controls/script.rb', line 95

def execute
  load_path_options = $LOAD_PATH.map do |load_path_entry|
    "-I#{load_path_entry}"
  end

  command = ["ruby", *load_path_options, "-e", source]

  Open3.capture3(*command)
end

#runObject



75
76
77
78
79
80
81
82
83
# File 'lib/constant/controls/script.rb', line 75

def run
  output, error_output, status = execute

  if not status.success?
    raise "Script failed\n\n#{source}\n#{error_output}"
  end

  output.split("\n")
end