hash_ids 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e6a52af0beb9680c0df6cae64443acf7a40dbd9c
4
- data.tar.gz: 04f672bc36f6772d3a723de505d05113de90af2f
3
+ metadata.gz: 05bd30a05b5b19148d5c898a0b14e8a24c7539ab
4
+ data.tar.gz: 353e8a9764a337b298f2bb0a2c8706ff7704a280
5
5
  SHA512:
6
- metadata.gz: 0cf493b119e120d849e9b15a078b0a80d928efcc103952b574f8130ce0ca01bb8b7a390a68077cacec06c62fe1ab06f585ea80b6532f02a58cf417bfed87091f
7
- data.tar.gz: 9a7fc89a22e818526965983db2b59547d425e51f4fb955ab76ae11a943e6de236078078228f227205a4266906c8c618dc22bb0574e9f3d274e0c0b27894dd806
6
+ metadata.gz: 2423e43afcf34b508464c99ea624267d3dbba9f494e0d3345d9e62c228340dd9c69eae6b7877568d208927edc3dabac11cf9f6f1b3f4ef5efc2a1f687dd6be6f
7
+ data.tar.gz: b7bd924bbb40bc374852c1a81ee0e2815e662730de3dca302225d3a8e00103e409cb9dd2450a79a61f72e240197afd78ffaf731d37611ba86dbe6c8c2681b980
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # HashIds
2
2
 
3
- TODO: Write a gem description
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
- TODO: Write usage instructions here
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
 
@@ -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
- columns_hash.include?(inheritance_column) ||
16
- args.first.kind_of?(Hash)
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.reject &:nil?
28
+ scope = scope.length==1 ? scope.first : scope
29
29
  end
30
30
  super(scope)
31
31
  end
@@ -1,3 +1,3 @@
1
1
  module HashIds
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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.2
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-03 00:00:00.000000000 Z
11
+ date: 2015-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashids