class Riddl::Utils::OAuth2::Helper::Tokens::File
Public Class Methods
Source
# File lib/ruby/riddl/utils/oauth2-helper.rb, line 58 def initialize(tfile) @tfile = tfile @changed = changed read end
Public Instance Methods
Source
# File lib/ruby/riddl/utils/oauth2-helper.rb, line 116 def delete(token) deleted = @tokens.delete(token) write deleted end
Source
# File lib/ruby/riddl/utils/oauth2-helper.rb, line 73 def each if block_given? @tokens.each do |k,v| yield k,v end else @tokens.each end end
Source
# File lib/ruby/riddl/utils/oauth2-helper.rb, line 68 def get(key) read if changed != @changed @tokens[key] end
Source
# File lib/ruby/riddl/utils/oauth2-helper.rb, line 83 def key?(key) @tokens.key?(key) end
Source
# File lib/ruby/riddl/utils/oauth2-helper.rb, line 87 def set(key,value,dur) @tokens[key] = value write nil end
Private Instance Methods
Source
# File lib/ruby/riddl/utils/oauth2-helper.rb, line 93 def changed if ::File.exist?(@tfile) ::File.stat(@tfile).mtime else @tokens = {} write end end
Source
# File lib/ruby/riddl/utils/oauth2-helper.rb, line 111 def read @tokens = JSON::parse(::File.read(@tfile)) rescue {} end
Source
# File lib/ruby/riddl/utils/oauth2-helper.rb, line 103 def write EM.defer { ::File.write(@tfile, JSON::pretty_generate(@tokens)) rescue {} } @changed = changed end