obfuscate_id 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -9
- data/lib/obfuscate_id.rb +4 -12
- data/lib/obfuscate_id/version.rb +1 -1
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24b7a1499df1324802389a6739e7f3f69fd1eabc
|
4
|
+
data.tar.gz: e698a140425dab9ee1daaca4c543b2f2672f8904
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54232a971eae2032e125f0b23f4fff24292bfcaa8df29e046b71f42eb670a20f7cec936b981c3bb66d99fcb75c927c583928403c59dc0f23a89ad97bd7b42f8a
|
7
|
+
data.tar.gz: 154be515758af5ac816bbae57f36c1a3fd815388063339441424d8864fc85bc8eea65667ded352864fd0555555323024376ecbdfb61f85ed25c22a3814cf2e76
|
data/README.md
CHANGED
@@ -13,7 +13,7 @@ obfuscate_id turns a URL like this:
|
|
13
13
|
into something like:
|
14
14
|
|
15
15
|
http://example.com/users/2356513904
|
16
|
-
|
16
|
+
|
17
17
|
Sequential ActiveRecord ids become non-sequential, random looking, numeric ids.
|
18
18
|
|
19
19
|
# post 7000
|
@@ -22,7 +22,7 @@ Sequential ActiveRecord ids become non-sequential, random looking, numeric ids.
|
|
22
22
|
http://example.com/posts/7107163820
|
23
23
|
# post 7002
|
24
24
|
http://example.com/posts/3296163828
|
25
|
-
|
25
|
+
|
26
26
|
## Why would you want this?
|
27
27
|
|
28
28
|
If your site is scaling well, you might not want to leak that you are getting 50 new posts a minute.
|
@@ -52,7 +52,7 @@ Run bundler.
|
|
52
52
|
|
53
53
|
## Usage
|
54
54
|
|
55
|
-
In your model, add a single line.
|
55
|
+
In your model, add a single line.
|
56
56
|
|
57
57
|
class Post < ActiveRecord::Base
|
58
58
|
obfuscate_id
|
@@ -81,6 +81,12 @@ ActiveRecord reverses this obfuscated id back to the plain id before building th
|
|
81
81
|
* This is not security. obfuscate_id was created to lightly mask record id numbers for the casual user. If you need to really secure your database ids (hint, you probably don't), you need to use real encryption like AES.
|
82
82
|
* To properly generate obfuscated urls, make sure you trigger the model's `to_param` method by passing in the whole object rather than just the id; do this: `post_path(@post)` not this: `post_path(@post.id)`.
|
83
83
|
|
84
|
+
## Versions
|
85
|
+
|
86
|
+
This is tested with Rails 4.2.0. For other versions of Rails, please see [the releases](https://github.com/namick/obfuscate_id/releases).
|
87
|
+
|
88
|
+
If you are trying to get it to work with a different version of rails that is not tested, let me know in [the issues](https://github.com/namick/obfuscate_id/issues)
|
89
|
+
|
84
90
|
## Development
|
85
91
|
|
86
92
|
To run the tests, first clone the repo and run bundler:
|
@@ -89,12 +95,6 @@ To run the tests, first clone the repo and run bundler:
|
|
89
95
|
cd obfuscate_id
|
90
96
|
bundle install
|
91
97
|
|
92
|
-
Change to the dummy rails app and load the test database
|
93
|
-
|
94
|
-
cd spec/dummy
|
95
|
-
bundle exec rake db:test:load
|
96
|
-
cd -
|
97
|
-
|
98
98
|
Run the tests
|
99
99
|
|
100
100
|
bundle exec rspec spec
|
data/lib/obfuscate_id.rb
CHANGED
@@ -59,15 +59,11 @@ module ObfuscateId
|
|
59
59
|
|
60
60
|
# As ActiveRecord::Persistence#reload uses self.id
|
61
61
|
# reload without deobfuscating
|
62
|
-
# def reload(options = nil)
|
63
|
-
# options = (options || {}).merge(:no_obfuscated_id => true)
|
64
|
-
# super(options)
|
65
|
-
# end
|
66
|
-
|
67
62
|
def reload(options = nil)
|
68
|
-
options = (options || {}).merge(:
|
63
|
+
options = (options || {}).merge(no_obfuscated_id: true)
|
69
64
|
clear_aggregation_cache
|
70
65
|
clear_association_cache
|
66
|
+
|
71
67
|
fresh_object =
|
72
68
|
if options && options[:lock]
|
73
69
|
self.class.unscoped { self.class.lock(options[:lock]).find(id, options) }
|
@@ -75,12 +71,8 @@ module ObfuscateId
|
|
75
71
|
self.class.unscoped { self.class.find(id, options) }
|
76
72
|
end
|
77
73
|
|
78
|
-
@attributes
|
79
|
-
|
80
|
-
@column_types = self.class.column_types
|
81
|
-
@column_types_override = fresh_object.instance_variable_get('@column_types_override')
|
82
|
-
@attributes_cache = {}
|
83
|
-
@new_record = false
|
74
|
+
@attributes = fresh_object.instance_variable_get('@attributes')
|
75
|
+
@new_record = false
|
84
76
|
self
|
85
77
|
end
|
86
78
|
|
data/lib/obfuscate_id/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: obfuscate_id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Amick
|
@@ -30,28 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 4.
|
33
|
+
version: 4.2.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 4.
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: activeresource
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 4.0.0
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 4.0.0
|
40
|
+
version: 4.2.0
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: sqlite3
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|