class HammerCLIForeman::Session

Attributes

auth_type[RW]
id[RW]
user_name[RW]

Public Class Methods

new(session_path) click to toggle source
# File lib/hammer_cli_foreman/sessions.rb, line 60
def initialize(session_path)
  @session_path = File.expand_path(session_path)
  if File.exist?(@session_path) && !File.zero?(@session_path)
    session_data = JSON.parse(File.read(@session_path))
    @id = session_data['id']
    @user_name = session_data['user_name']
    @auth_type = session_data['auth_type']
  end
rescue JSON::ParserError
  warn _('Invalid session data. Resetting the session.')
end

Public Instance Methods

destroy() click to toggle source
# File lib/hammer_cli_foreman/sessions.rb, line 83
def destroy
  @id = nil
  store
end
store() click to toggle source
# File lib/hammer_cli_foreman/sessions.rb, line 72
def store
  File.open(@session_path,"w") do |f|
    f.write({
      id: id,
      auth_type: auth_type,
      user_name: user_name
    }.to_json)
  end
  File.chmod(0600, @session_path)
end
valid?() click to toggle source
# File lib/hammer_cli_foreman/sessions.rb, line 88
def valid?
  !id.nil? && !id.empty?
end