Sha256: d250d9689c337fa78d353867da4ee73b45e8e1fa0755b917c7fc83c94f30a9e5
Contents?: true
Size: 734 Bytes
Versions: 2
Compression:
Stored size: 734 Bytes
Contents
require "securerandom" require "moneta" require "urb/middleware" require "urb/engine" if defined?(Rails::Engine) require "urb/version" module URB extend self CHARS = [*0..9, *"A".."Z", *"a".."z"] PATH = "/-/" PREFIX = "@" MAXLENGTH = 2000 def config(*args) @config = args end def fetch(key) paths[key] end def store(path) value = "#{PREFIX}#{path}" paths[value] || begin generate_key.tap do |key| paths[key] = path paths[value] = key end end end private def paths @paths ||= Moneta.new *(@config || [:Memory]) end def generate_key SecureRandom.urlsafe_base64(6).gsub(/[_-]/){ CHARS.sample } end end def URB(*args) URB.config *args end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
urb-0.1.5 | lib/urb.rb |
urb-0.1.4 | lib/urb.rb |