Class: DomoscioRails::AuthorizationToken::FileStorage
- Inherits:
-
Object
- Object
- DomoscioRails::AuthorizationToken::FileStorage
- Defined in:
- lib/domoscio_rails/authorization_token.rb
Overview
Manages tokens with local File
Instance Method Summary collapse
- #file_path ⇒ Object
- #get ⇒ Object
-
#initialize ⇒ FileStorage
constructor
A new instance of FileStorage.
- #store(token) ⇒ Object
Constructor Details
#initialize ⇒ FileStorage
Returns a new instance of FileStorage.
35 36 37 |
# 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 |
Instance Method Details
#file_path ⇒ Object
58 59 60 |
# File 'lib/domoscio_rails/authorization_token.rb', line 58 def file_path File.join(DomoscioRails.configuration.temp_dir, 'DomoscioRails.AuthorizationToken.FileStore.tmp') end |
#get ⇒ Object
39 40 41 42 43 44 45 46 47 |
# 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.load(txt) || nil rescue Errno::ENOENT nil end |
#store(token) ⇒ Object
49 50 51 52 53 54 55 56 |
# 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 |