prefixed_ids 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38b6a59341fa7c4d02fdaba7f6eb738cdb5730a9aa6caca89ffb89bfa9dc4740
4
- data.tar.gz: ae7de74cf643796ce5fdafe5e0b7d0db98cf60b761a52a960ad1122c14028b0a
3
+ metadata.gz: e306f564334470e61f4181b498ace781d12d7d06d1763dfa72a1b8a5f464ecaf
4
+ data.tar.gz: 79118c8868ffd9244eccc1929aef505c73d79d85df8de9e1a3a07b07225e4c1a
5
5
  SHA512:
6
- metadata.gz: 428331d371bbcc87c9d092297b315476ccd9e62548ff59efef59cb7a3574b256247f4dacf6c1edc3c2f72e553a742033493f51587af264707a77ca3d797cea9e
7
- data.tar.gz: af9b8a1f596b9b6d1720e8ec71b267421d6c0df5fd661e0b3b76765d8606bb929e5bf2a2bbe81a9fd853290e4e1a844ca7d3a63ad25001da9d9eb9beb3a98c0b
6
+ metadata.gz: 66299e3e87f3495ddc7cb973da3cfa60104a6b1d0418f1a9c66e5ae9a2c0311689fa40aa0376e239ac8489a034a2b9fcb503e5aa11def29d818660615fbed958
7
+ data.tar.gz: 13f65f23972ca2a38038f00007802ce4d65b163e15b990b15d4b1fdb8f9421d032167722bf181810cfaa281527b321cd4fec0317855f68ca8726aad8461e3244
data/README.md CHANGED
@@ -34,7 +34,23 @@ end
34
34
 
35
35
  This will generate a value like `user_1234abcd`.
36
36
 
37
- To query using the prefixed ID, simply you can use either `find` or `find_by_prefixed_id`:
37
+ ##### Prefix ID Param
38
+
39
+ To retrieve the prefix ID, simply call:
40
+
41
+ ```ruby
42
+ User.to_param
43
+ ```
44
+
45
+ If `to_param` override is disabled:
46
+
47
+ ```ruby
48
+ User.prefix_id
49
+ ```
50
+
51
+ ##### Query by Prefixed ID
52
+
53
+ To query using the prefixed ID, you can use either `find` or `find_by_prefix_id`:
38
54
 
39
55
  ```ruby
40
56
  User.find("user_5vJjbzXq9KrLEMm32iAnOP0xGDYk6dpe")
@@ -51,7 +67,26 @@ class User < ApplicationRecord
51
67
  end
52
68
  ```
53
69
 
54
- ### Generic lookup
70
+ ##### Salt
71
+
72
+ A salt is a secret value that makes it impossible to reverse engineer IDs. We recommend adding a salt to make your Prefix IDs unguessable.
73
+
74
+ ###### Global Salt
75
+
76
+ ```ruby
77
+ # config/initializers/prefixed_ids.rb
78
+ PrefixID.salt = "salt"
79
+ ```
80
+
81
+ ###### Per Model Salt
82
+
83
+ ```ruby
84
+ class User
85
+ has_prefix_id :user, salt: "usersalt"
86
+ end
87
+ ```
88
+
89
+ ### Generic Lookup By Prefix ID
55
90
 
56
91
  Imagine you have a prefixed ID but you don't know which model it belongs to.
57
92
 
@@ -62,13 +97,13 @@ PrefixedIds.find("acct_2iAnOP0xGDYk6dpe")
62
97
  #=> #<Account>
63
98
  ```
64
99
 
65
- ### Customizing
100
+ ### Customizing Prefix IDs
66
101
 
67
102
  You can customize the prefix, length, and attribute name for PrefixedIds.
68
103
 
69
104
  ```ruby
70
105
  class Account < ApplicationRecord
71
- has_prefix_id :acct, minimum_length: 32, override_find: false, to_param: false
106
+ has_prefix_id :acct, minimum_length: 32, override_find: false, to_param: false, salt: ""
72
107
  end
73
108
  ```
74
109
 
@@ -4,10 +4,10 @@ module PrefixedIds
4
4
 
5
5
  TOKEN = 123
6
6
 
7
- def initialize(model, prefix, minimum_length: PrefixedIds.minimum_length, alphabet: PrefixedIds.alphabet, delimiter: PrefixedIds.delimiter, **options)
7
+ def initialize(model, prefix, salt: PrefixedIds.salt, minimum_length: PrefixedIds.minimum_length, alphabet: PrefixedIds.alphabet, delimiter: PrefixedIds.delimiter, **options)
8
8
  @prefix = prefix.to_s
9
9
  @delimiter = delimiter.to_s
10
- @hashids = Hashids.new(model.table_name, minimum_length, alphabet)
10
+ @hashids = Hashids.new("#{model.table_name}#{salt}", minimum_length, alphabet)
11
11
  end
12
12
 
13
13
  def encode(id)
@@ -1,3 +1,3 @@
1
1
  module PrefixedIds
2
- VERSION = "1.2.2"
2
+ VERSION = "1.3.0"
3
3
  end
data/lib/prefixed_ids.rb CHANGED
@@ -11,6 +11,7 @@ module PrefixedIds
11
11
  mattr_accessor :delimiter, default: "_"
12
12
  mattr_accessor :alphabet, default: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
13
13
  mattr_accessor :minimum_length, default: 24
14
+ mattr_accessor :salt, default: ""
14
15
 
15
16
  mattr_accessor :models, default: {}
16
17
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prefixed_ids
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-03 00:00:00.000000000 Z
11
+ date: 2022-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -45,7 +45,7 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: 2.0.0
47
47
  - !ruby/object:Gem::Dependency
48
- name: standardrb
48
+ name: standard
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="
@@ -86,7 +86,6 @@ files:
86
86
  - lib/prefixed_ids/engine.rb
87
87
  - lib/prefixed_ids/prefix_id.rb
88
88
  - lib/prefixed_ids/version.rb
89
- - lib/tasks/prefixed_ids_tasks.rake
90
89
  homepage: https://github.com/excid3/prefixed_ids
91
90
  licenses:
92
91
  - MIT
@@ -109,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
108
  - !ruby/object:Gem::Version
110
109
  version: '0'
111
110
  requirements: []
112
- rubygems_version: 3.2.3
111
+ rubygems_version: 3.3.7
113
112
  signing_key:
114
113
  specification_version: 4
115
114
  summary: Prefixed IDs generates IDs with friendly prefixes for your models
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :prefixed_ids do
3
- # # Task goes here
4
- # end