Class: SessionAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/adapters/session_adapter.rb

Constant Summary collapse

FILE_LOCATION =
'~/.ccli/session'

Instance Method Summary collapse

Instance Method Details

#clear_sessionObject



30
31
32
33
34
# File 'lib/adapters/session_adapter.rb', line 30

def clear_session
  return unless ccli_directory_exists?

  FileUtils.rm_r(ccli_directory_path)
end

#selected_folderObject



36
37
38
# File 'lib/adapters/session_adapter.rb', line 36

def selected_folder
  @selected_folder ||= Folder.find(selected_folder_id)
end

#session_dataObject



24
25
26
27
28
# File 'lib/adapters/session_adapter.rb', line 24

def session_data
  raise SessionMissingError unless session_file_exists?

  @session_data ||= Psych.load_file(session_file_path)
end

#update_session(session) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/adapters/session_adapter.rb', line 13

def update_session(session)
  session.merge!(session_data) { |_key, input| input } if session_file_exists?

  FileUtils.mkdir_p ccli_directory_path unless ccli_directory_exists?
  File.open(session_file_path, 'w') do |file|
    session.merge!(extracted_token(session[:encoded_token])) { |_key, _v1, v2| v2 }
    session.delete(:encoded_token)
    file.write session.to_yaml
  end
end