Class: HammerCLIForeman::Session
- Inherits:
-
Object
- Object
- HammerCLIForeman::Session
- Defined in:
- lib/hammer_cli_foreman/sessions.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#user_name ⇒ Object
Returns the value of attribute user_name.
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(session_path) ⇒ Session
constructor
A new instance of Session.
- #store ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(session_path) ⇒ Session
Returns a new instance of Session.
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/hammer_cli_foreman/sessions.rb', line 60 def initialize(session_path) @session_path = File.(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'] end rescue JSON::ParserError warn _('Invalid session data. Resetting the session.') end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
58 59 60 |
# File 'lib/hammer_cli_foreman/sessions.rb', line 58 def id @id end |
#user_name ⇒ Object
Returns the value of attribute user_name.
58 59 60 |
# File 'lib/hammer_cli_foreman/sessions.rb', line 58 def user_name @user_name end |
Instance Method Details
#destroy ⇒ Object
81 82 83 84 |
# File 'lib/hammer_cli_foreman/sessions.rb', line 81 def destroy @id = nil store end |
#store ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/hammer_cli_foreman/sessions.rb', line 71 def store File.open(@session_path,"w") do |f| f.write({ id: id, user_name: user_name }.to_json) end File.chmod(0600, @session_path) end |
#valid? ⇒ Boolean
86 87 88 |
# File 'lib/hammer_cli_foreman/sessions.rb', line 86 def valid? !id.nil? && !id.empty? end |