class Riddl::Utils::OAuth2::Helper::Tokens::File

Public Class Methods

new(tfile) click to toggle source
# File lib/ruby/riddl/utils/oauth2-helper.rb, line 58
def initialize(tfile)
  @tfile = tfile
  @changed = changed
  read
end

Public Instance Methods

[](key) click to toggle source
# File lib/ruby/riddl/utils/oauth2-helper.rb, line 64
def [](key)
  get(key)
end
delete(token) click to toggle source
# File lib/ruby/riddl/utils/oauth2-helper.rb, line 116
def delete(token)
  deleted = @tokens.delete(token)
  write
  deleted
end
each() { |k,v| ... } click to toggle 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
get(key) click to toggle source
# File lib/ruby/riddl/utils/oauth2-helper.rb, line 68
def get(key)
  read if changed != @changed
  @tokens[key]
end
key?(key) click to toggle source
# File lib/ruby/riddl/utils/oauth2-helper.rb, line 83
def key?(key)
  @tokens.key?(key)
end
set(key,value,dur) click to toggle 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

changed() click to toggle 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
read() click to toggle source
# File lib/ruby/riddl/utils/oauth2-helper.rb, line 111
def read
  @tokens = JSON::parse(::File.read(@tfile)) rescue {}
end
write() click to toggle 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