Class: MangoPay::AuthorizationToken::FileStorage
- Inherits:
-
Object
- Object
- MangoPay::AuthorizationToken::FileStorage
- Defined in:
- lib/mangopay/authorization_token.rb
Instance Method Summary collapse
- #file_path ⇒ Object
- #get ⇒ Object
-
#initialize(temp_dir = nil) ⇒ FileStorage
constructor
A new instance of FileStorage.
- #store(token) ⇒ Object
Constructor Details
#initialize(temp_dir = nil) ⇒ FileStorage
Returns a new instance of FileStorage.
56 57 58 59 60 61 |
# File 'lib/mangopay/authorization_token.rb', line 56 def initialize(temp_dir = nil) @temp_dir = temp_dir || MangoPay.configuration.temp_dir if !@temp_dir raise "Path to temporary folder is not defined" end end |
Instance Method Details
#file_path ⇒ Object
84 85 86 |
# File 'lib/mangopay/authorization_token.rb', line 84 def file_path File.join(@temp_dir, "MangoPay.AuthorizationToken.FileStore.tmp") end |
#get ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/mangopay/authorization_token.rb', line 63 def get begin 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 end |
#store(token) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/mangopay/authorization_token.rb', line 75 def store(token) File.open(file_path, File::RDWR | File::CREAT, 0644) do |f| f.flock(File::LOCK_EX) f.truncate(0) f.rewind f.puts(YAML.dump(token)) end end |