Class: Yast::HooksClass::HookFile

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
library/general/src/modules/Hooks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ HookFile

Returns a new instance of HookFile.


205
206
207
# File 'library/general/src/modules/Hooks.rb', line 205

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path


203
204
205
# File 'library/general/src/modules/Hooks.rb', line 203

def path
  @path
end

#resultObject (readonly)

Returns the value of attribute result


203
204
205
# File 'library/general/src/modules/Hooks.rb', line 203

def result
  @result
end

Instance Method Details

#contentObject


216
217
218
# File 'library/general/src/modules/Hooks.rb', line 216

def content
  @content ||= ::File.read(path)
end

#executeObject


209
210
211
212
213
214
# File 'library/general/src/modules/Hooks.rb', line 209

def execute
  log.info "Executing hook file '#{path}'"
  @result = OpenStruct.new(SCR.Execute(Path.new(".target.bash_output"), path.to_s.shellescape))
  log.error "Hook file '#{path.basename}' failed with stderr: #{result.stderr}" if failed?
  result
end

#failed?Boolean

Returns:

  • (Boolean)

233
234
235
# File 'library/general/src/modules/Hooks.rb', line 233

def failed?
  !succeeded?
end

#outputObject


220
221
222
223
224
225
226
227
# File 'library/general/src/modules/Hooks.rb', line 220

def output
  return "" unless result

  output = []
  output << "STDERR: #{result.stderr.strip}" unless result.stderr.empty?
  output << "STDOUT: #{result.stdout.strip}" unless result.stdout.empty?
  output.join("; ")
end

#succeeded?Boolean

Returns:

  • (Boolean)

229
230
231
# File 'library/general/src/modules/Hooks.rb', line 229

def succeeded?
  result.exit.zero?
end