module ForemanMaintain::Concerns::Systemd

Public Instance Methods

action_noun(action) click to toggle source
# File lib/foreman_maintain/concerns/systemd.rb, line 4
def action_noun(action)
  action_word_modified(action) + 'ing'
end
action_past_tense(action) click to toggle source
# File lib/foreman_maintain/concerns/systemd.rb, line 8
def action_past_tense(action)
  action_word_modified(action) + 'ed'
end

Private Instance Methods

action_word_modified(action) click to toggle source
# File lib/foreman_maintain/concerns/systemd.rb, line 36
def action_word_modified(action)
  case action
  when 'status'
    'display'
  when 'enable', 'disable'
    action.chomp('e')
  when 'stop'
    action + 'p'
  else
    action
  end
end
allowed_action?(action) click to toggle source
# File lib/foreman_maintain/concerns/systemd.rb, line 32
def allowed_action?(action)
  %w[start stop restart status enable disable].include?(action)
end
format_brief_status(exit_code) click to toggle source
# File lib/foreman_maintain/concerns/systemd.rb, line 26
def format_brief_status(exit_code)
  result = (exit_code == 0) ? reporter.status_label(:success) : reporter.status_label(:fail)
  padding = reporter.max_length - reporter.last_line.to_s.length - 30
  "#{' ' * padding} #{result}"
end
format_status(output, exit_code, options) click to toggle source
# File lib/foreman_maintain/concerns/systemd.rb, line 14
def format_status(output, exit_code, options)
  status = ''
  if !options[:failing] || exit_code > 0
    if options[:brief]
      status += format_brief_status(exit_code)
    elsif !(output.nil? || output.empty?)
      status += "\n" + output
    end
  end
  status
end