hash_ids 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -2
- data/lib/hash_ids/obfuscate.rb +5 -5
- data/lib/hash_ids/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05bd30a05b5b19148d5c898a0b14e8a24c7539ab
|
4
|
+
data.tar.gz: 353e8a9764a337b298f2bb0a2c8706ff7704a280
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2423e43afcf34b508464c99ea624267d3dbba9f494e0d3345d9e62c228340dd9c69eae6b7877568d208927edc3dabac11cf9f6f1b3f4ef5efc2a1f687dd6be6f
|
7
|
+
data.tar.gz: b7bd924bbb40bc374852c1a81ee0e2815e662730de3dca302225d3a8e00103e409cb9dd2450a79a61f72e240197afd78ffaf731d37611ba86dbe6c8c2681b980
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# HashIds
|
2
2
|
|
3
|
-
|
3
|
+
Obfuscate your id in the air
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -20,7 +20,36 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
23
|
+
|
24
|
+
```
|
25
|
+
# create config/initializers/hashids.rb
|
26
|
+
|
27
|
+
HashIds.config do |config|
|
28
|
+
config.salt = 'secret salt'
|
29
|
+
config.min_hash_length = 12 # id length
|
30
|
+
config.alphabet = 'abcd12345' # random char pool require at least 16 unique characters
|
31
|
+
end
|
32
|
+
|
33
|
+
# add hash_as_id to model
|
34
|
+
|
35
|
+
class User < ActiveRecord::Base
|
36
|
+
hash_as_id
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
*Notice* please use `user_path(@user)` instead of `user_path(@user.id)`
|
41
|
+
|
42
|
+
```
|
43
|
+
User.find "qeYay1x5bLKVMk5z"
|
44
|
+
=> [#<User id: 2, name: "some guy", created_at: "2015-02-03 07:11:14", updated_at: "2015-02-03 07:11:14">]
|
45
|
+
|
46
|
+
User.find 2
|
47
|
+
=> [#<User id: 2, name: "some guy", created_at: "2015-02-03 07:11:14", updated_at: "2015-02-03 07:11:14">]
|
48
|
+
|
49
|
+
app.user_path(User.last)
|
50
|
+
=> "/users/6n9w75n65da8"
|
51
|
+
```
|
52
|
+
|
24
53
|
|
25
54
|
## Contributing
|
26
55
|
|
data/lib/hash_ids/obfuscate.rb
CHANGED
@@ -10,14 +10,14 @@ module HashIds
|
|
10
10
|
module ClassMethods
|
11
11
|
|
12
12
|
def super_able? args
|
13
|
-
primary_key.nil? ||
|
13
|
+
primary_key.nil? ||
|
14
14
|
default_scopes.any? ||
|
15
|
-
|
16
|
-
args.first.kind_of?(
|
15
|
+
args.first.kind_of?(Hash) ||
|
16
|
+
args.first.kind_of?(Symbol) ||
|
17
|
+
columns_hash.include?(inheritance_column)
|
17
18
|
end
|
18
19
|
|
19
20
|
def find(*args)
|
20
|
-
return super if args.first.kind_of?(Symbol)
|
21
21
|
return super if block_given? || super_able?(args)
|
22
22
|
|
23
23
|
scope = args
|
@@ -25,7 +25,7 @@ module HashIds
|
|
25
25
|
scope.map! do |id|
|
26
26
|
hash_ids?(id) ? hash_ids_decode(id).first : id
|
27
27
|
end
|
28
|
-
scope.
|
28
|
+
scope = scope.length==1 ? scope.first : scope
|
29
29
|
end
|
30
30
|
super(scope)
|
31
31
|
end
|
data/lib/hash_ids/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_ids
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kemingcao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashids
|