class DomoscioRails::AuthorizationToken::FileStorage

Manages tokens with local File

Public Class Methods

new() click to toggle source
# File lib/domoscio_rails/authorization_token.rb, line 35
def initialize
  raise 'Path to temporary folder is not defined' unless DomoscioRails.configuration.temp_dir
end

Public Instance Methods

file_path() click to toggle source
# File lib/domoscio_rails/authorization_token.rb, line 58
def file_path
  File.join(DomoscioRails.configuration.temp_dir, 'DomoscioRails.AuthorizationToken.FileStore.tmp')
end
get() click to toggle source
# File lib/domoscio_rails/authorization_token.rb, line 39
def get
  f = File.open(file_path, File::RDONLY)
  f.flock(File::LOCK_SH)
  txt = f.read
  f.close
  YAML.safe_load(txt) || nil
rescue Errno::ENOENT
  nil
end
store(token) click to toggle source
# File lib/domoscio_rails/authorization_token.rb, line 49
def store(token)
  File.open(file_path, File::RDWR|File::CREAT, 0o644) do |f|
    f.flock(File::LOCK_EX)
    f.truncate(0)
    f.rewind
    f.puts(YAML.dump(token))
  end
end