class UrlStore

Constants

IN

(convert to base64url <-> RFC4648) and '|' which is not url-safe if you ask ERB/CGI, but browsers accept it

OUT
SECRET
VERSION

Public Class Methods

decode(string) click to toggle source
# File lib/url_store.rb, line 20
def self.decode(string)
  new.decode(string)
end
defaults=(x) click to toggle source
# File lib/url_store.rb, line 14
def self.defaults=(x); @@defaults=x; end
encode(data) click to toggle source
# File lib/url_store.rb, line 16
def self.encode(data)
  new.encode(data)
end
new(options={}) click to toggle source
# File lib/url_store.rb, line 24
def initialize(options={})
  @options = @@defaults.merge(options)
end

Public Instance Methods

decode(string) click to toggle source
# File lib/url_store.rb, line 33
def decode(string)
  string = string.to_s.tr(OUT,IN) # convert to base64url <-> RFC4648
  encoder.decode(string)
end
encode(data) click to toggle source
# File lib/url_store.rb, line 28
def encode(data)
  string = encoder.encode(data)
  string.to_s.tr(IN,OUT)
end

Private Instance Methods

encoder() click to toggle source
# File lib/url_store.rb, line 40
def encoder
  options = {:secret => SECRET}.merge(@options)
  if options[:secret] == SECRET
    warn "WARNING: You are using the default secret! Set your own with UrlStore.defaults = {:secret => 'something'}"
  end
  UrlStore::CompactEncoder.new(options)
end