opaque_id 1.7.7 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/opaque_id/configuration.rb +17 -0
- data/lib/opaque_id/model.rb +6 -6
- data/lib/opaque_id/version.rb +1 -1
- data/lib/opaque_id.rb +13 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a40ad63944daaeefb792cac08d0d7365b5fe474aa79f5865939ce01d4c7f5af7
|
|
4
|
+
data.tar.gz: 373d7b970155ac9a33b079e854904e290a1209298520506fd8d69a7f93c5ec61
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 849a8801e120cc20299cfcf3e132968ad4f35e6b3cd2b5bfac2620aee5b597db765a59b175f9237d1a37fce91177701387d05c22bdd9dc9bca127f1b054ab8c6
|
|
7
|
+
data.tar.gz: 71876e010c96d8f1f0d0a9d10fca158987122b747abc587560b171c32253404524b0541e337394212a899a6b0ec9be6db51ac973030834eee6ca9084f498040e
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OpaqueId
|
|
4
|
+
class Configuration
|
|
5
|
+
attr_accessor :default_length, :default_alphabet, :default_column,
|
|
6
|
+
:default_require_letter_start, :default_purge_chars, :default_max_retry
|
|
7
|
+
|
|
8
|
+
def initialize
|
|
9
|
+
@default_length = 18
|
|
10
|
+
@default_alphabet = OpaqueId::SLUG_LIKE_ALPHABET
|
|
11
|
+
@default_column = :opaque_id
|
|
12
|
+
@default_require_letter_start = false
|
|
13
|
+
@default_purge_chars = []
|
|
14
|
+
@default_max_retry = 3
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/opaque_id/model.rb
CHANGED
|
@@ -22,7 +22,7 @@ module OpaqueId
|
|
|
22
22
|
|
|
23
23
|
# Configuration options
|
|
24
24
|
def opaque_id_column
|
|
25
|
-
@opaque_id_column ||=
|
|
25
|
+
@opaque_id_column ||= OpaqueId.configuration.default_column
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def opaque_id_column=(value)
|
|
@@ -30,7 +30,7 @@ module OpaqueId
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def opaque_id_length
|
|
33
|
-
@opaque_id_length ||=
|
|
33
|
+
@opaque_id_length ||= OpaqueId.configuration.default_length
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def opaque_id_length=(value)
|
|
@@ -38,7 +38,7 @@ module OpaqueId
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def opaque_id_alphabet
|
|
41
|
-
@opaque_id_alphabet ||= OpaqueId
|
|
41
|
+
@opaque_id_alphabet ||= OpaqueId.configuration.default_alphabet
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
def opaque_id_alphabet=(value)
|
|
@@ -46,7 +46,7 @@ module OpaqueId
|
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
def opaque_id_require_letter_start
|
|
49
|
-
@opaque_id_require_letter_start ||=
|
|
49
|
+
@opaque_id_require_letter_start ||= OpaqueId.configuration.default_require_letter_start
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
def opaque_id_require_letter_start=(value)
|
|
@@ -54,7 +54,7 @@ module OpaqueId
|
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
def opaque_id_purge_chars
|
|
57
|
-
@opaque_id_purge_chars ||=
|
|
57
|
+
@opaque_id_purge_chars ||= OpaqueId.configuration.default_purge_chars
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
def opaque_id_purge_chars=(value)
|
|
@@ -62,7 +62,7 @@ module OpaqueId
|
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
def opaque_id_max_retry
|
|
65
|
-
@opaque_id_max_retry ||=
|
|
65
|
+
@opaque_id_max_retry ||= OpaqueId.configuration.default_max_retry
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
def opaque_id_max_retry=(value)
|
data/lib/opaque_id/version.rb
CHANGED
data/lib/opaque_id.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'securerandom'
|
|
4
4
|
require_relative 'opaque_id/version'
|
|
5
|
+
require_relative 'opaque_id/configuration'
|
|
5
6
|
require_relative 'opaque_id/model'
|
|
6
7
|
|
|
7
8
|
module OpaqueId
|
|
@@ -19,6 +20,18 @@ module OpaqueId
|
|
|
19
20
|
ALPHANUMERIC_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
|
20
21
|
|
|
21
22
|
class << self
|
|
23
|
+
def configuration
|
|
24
|
+
@configuration ||= Configuration.new
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def configure
|
|
28
|
+
yield(configuration)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def reset_configuration!
|
|
32
|
+
@configuration = Configuration.new
|
|
33
|
+
end
|
|
34
|
+
|
|
22
35
|
# Generate a cryptographically secure random ID
|
|
23
36
|
def generate(size: 18, alphabet: SLUG_LIKE_ALPHABET)
|
|
24
37
|
raise ConfigurationError, 'Size must be positive' unless size.positive?
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: opaque_id
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Joe Nyaggah
|
|
@@ -122,6 +122,7 @@ files:
|
|
|
122
122
|
- lib/generators/opaque_id/install_generator.rb
|
|
123
123
|
- lib/generators/opaque_id/templates/migration.rb.tt
|
|
124
124
|
- lib/opaque_id.rb
|
|
125
|
+
- lib/opaque_id/configuration.rb
|
|
125
126
|
- lib/opaque_id/model.rb
|
|
126
127
|
- lib/opaque_id/version.rb
|
|
127
128
|
homepage: https://github.com/nyaggah/opaque_id
|