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.



207
208
209
# File 'library/general/src/modules/Hooks.rb', line 207

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#resultObject (readonly)

Returns the value of attribute result.



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

def result
  @result
end

Instance Method Details

#contentObject



218
219
220
# File 'library/general/src/modules/Hooks.rb', line 218

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

#executeObject



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

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)


235
236
237
# File 'library/general/src/modules/Hooks.rb', line 235

def failed?
  !succeeded?
end

#outputObject



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

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)


231
232
233
# File 'library/general/src/modules/Hooks.rb', line 231

def succeeded?
  result.exit.zero?
end