forked from jpmcgrath/shortener
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshortener.rb
39 lines (30 loc) · 1.08 KB
/
shortener.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require "active_support/dependencies"
module Shortener
autoload :ActiveRecordExtension, "shortener/active_record_extension"
autoload :ShortenUrlInterceptor, "shortener/shorten_url_interceptor"
CHARSETS = {
alphanum: ('a'..'z').to_a + (0..9).to_a,
alphanumcase: ('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a,
alphanumcaseplus: ('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a + ['~', '_']
}
# default key length: 5 characters
mattr_accessor :unique_key_length
self.unique_key_length = 5
# character set to chose from:
# :alphanum - a-z0-9 - has about 60 million possible combos
# :alphanumcase - a-zA-Z0-9 - has about 900 million possible combos
mattr_accessor :charset
self.charset = :alphanumcaseplus
#The default redirection url when the key isn't found
mattr_accessor :default_redirect
self.default_redirect = '/'
# forbidden keys
mattr_accessor :forbidden_keys
self.forbidden_keys = []
def self.key_chars
CHARSETS[charset]
end
end
# Require our railtie and engine
require "shortener/railtie"
require "shortener/engine"