hash_ids 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{LICENSE.txt → MIT-LICENSE} +1 -3
- data/Rakefile +23 -4
- data/lib/hash_ids/obfuscate.rb +6 -5
- data/lib/hash_ids/version.rb +1 -1
- data/lib/hash_ids.rb +1 -0
- data/lib/tasks/hash_ids_tasks.rake +4 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/user.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/config/application.rb +32 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +41 -0
- data/spec/dummy/config/environments/production.rb +79 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +57 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20150204045322_create_users.rb +10 -0
- data/spec/dummy/db/schema.rb +23 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +16 -0
- data/spec/dummy/log/test.log +125 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/models/user_spec.rb +31 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/views/users_routes_spec.rb +19 -0
- metadata +100 -21
- data/.gitignore +0 -14
- data/.rspec +0 -2
- data/.travis.yml +0 -3
- data/Gemfile +0 -5
- data/README.md +0 -60
- data/hash_ids.gemspec +0 -25
- data/spec/hash_ids_spec.rb +0 -55
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kemingcao
|
@@ -11,49 +11,49 @@ cert_chain: []
|
|
11
11
|
date: 2015-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: hashids
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
34
|
-
type: :
|
33
|
+
version: '1.0'
|
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: '1.
|
40
|
+
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: sqlite3
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '1.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '1.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec
|
56
|
+
name: rspec-rails
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
@@ -73,20 +73,57 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
-
|
77
|
-
- ".rspec"
|
78
|
-
- ".travis.yml"
|
79
|
-
- Gemfile
|
80
|
-
- LICENSE.txt
|
81
|
-
- README.md
|
76
|
+
- MIT-LICENSE
|
82
77
|
- Rakefile
|
83
|
-
- hash_ids.gemspec
|
84
78
|
- lib/hash_ids.rb
|
85
79
|
- lib/hash_ids/configuration.rb
|
86
80
|
- lib/hash_ids/obfuscate.rb
|
87
81
|
- lib/hash_ids/version.rb
|
88
|
-
-
|
82
|
+
- lib/tasks/hash_ids_tasks.rake
|
83
|
+
- spec/dummy/README.rdoc
|
84
|
+
- spec/dummy/Rakefile
|
85
|
+
- spec/dummy/app/assets/javascripts/application.js
|
86
|
+
- spec/dummy/app/assets/stylesheets/application.css
|
87
|
+
- spec/dummy/app/controllers/application_controller.rb
|
88
|
+
- spec/dummy/app/helpers/application_helper.rb
|
89
|
+
- spec/dummy/app/models/user.rb
|
90
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
91
|
+
- spec/dummy/bin/bundle
|
92
|
+
- spec/dummy/bin/rails
|
93
|
+
- spec/dummy/bin/rake
|
94
|
+
- spec/dummy/bin/setup
|
95
|
+
- spec/dummy/config.ru
|
96
|
+
- spec/dummy/config/application.rb
|
97
|
+
- spec/dummy/config/boot.rb
|
98
|
+
- spec/dummy/config/database.yml
|
99
|
+
- spec/dummy/config/environment.rb
|
100
|
+
- spec/dummy/config/environments/development.rb
|
101
|
+
- spec/dummy/config/environments/production.rb
|
102
|
+
- spec/dummy/config/environments/test.rb
|
103
|
+
- spec/dummy/config/initializers/assets.rb
|
104
|
+
- spec/dummy/config/initializers/backtrace_silencers.rb
|
105
|
+
- spec/dummy/config/initializers/cookies_serializer.rb
|
106
|
+
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
107
|
+
- spec/dummy/config/initializers/inflections.rb
|
108
|
+
- spec/dummy/config/initializers/mime_types.rb
|
109
|
+
- spec/dummy/config/initializers/session_store.rb
|
110
|
+
- spec/dummy/config/initializers/wrap_parameters.rb
|
111
|
+
- spec/dummy/config/locales/en.yml
|
112
|
+
- spec/dummy/config/routes.rb
|
113
|
+
- spec/dummy/config/secrets.yml
|
114
|
+
- spec/dummy/db/development.sqlite3
|
115
|
+
- spec/dummy/db/migrate/20150204045322_create_users.rb
|
116
|
+
- spec/dummy/db/schema.rb
|
117
|
+
- spec/dummy/db/test.sqlite3
|
118
|
+
- spec/dummy/log/development.log
|
119
|
+
- spec/dummy/log/test.log
|
120
|
+
- spec/dummy/public/404.html
|
121
|
+
- spec/dummy/public/422.html
|
122
|
+
- spec/dummy/public/500.html
|
123
|
+
- spec/dummy/public/favicon.ico
|
124
|
+
- spec/models/user_spec.rb
|
89
125
|
- spec/spec_helper.rb
|
126
|
+
- spec/views/users_routes_spec.rb
|
90
127
|
homepage: https://github.com/kemingcao/hash_ids
|
91
128
|
licenses:
|
92
129
|
- MIT
|
@@ -112,5 +149,47 @@ signing_key:
|
|
112
149
|
specification_version: 4
|
113
150
|
summary: Obfuscate id like a foodie.
|
114
151
|
test_files:
|
115
|
-
- spec/
|
152
|
+
- spec/dummy/public/favicon.ico
|
153
|
+
- spec/dummy/public/404.html
|
154
|
+
- spec/dummy/public/500.html
|
155
|
+
- spec/dummy/public/422.html
|
156
|
+
- spec/dummy/log/test.log
|
157
|
+
- spec/dummy/log/development.log
|
158
|
+
- spec/dummy/config.ru
|
159
|
+
- spec/dummy/config/initializers/mime_types.rb
|
160
|
+
- spec/dummy/config/initializers/session_store.rb
|
161
|
+
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
162
|
+
- spec/dummy/config/initializers/wrap_parameters.rb
|
163
|
+
- spec/dummy/config/initializers/cookies_serializer.rb
|
164
|
+
- spec/dummy/config/initializers/inflections.rb
|
165
|
+
- spec/dummy/config/initializers/assets.rb
|
166
|
+
- spec/dummy/config/initializers/backtrace_silencers.rb
|
167
|
+
- spec/dummy/config/database.yml
|
168
|
+
- spec/dummy/config/routes.rb
|
169
|
+
- spec/dummy/config/application.rb
|
170
|
+
- spec/dummy/config/environment.rb
|
171
|
+
- spec/dummy/config/boot.rb
|
172
|
+
- spec/dummy/config/secrets.yml
|
173
|
+
- spec/dummy/config/environments/development.rb
|
174
|
+
- spec/dummy/config/environments/test.rb
|
175
|
+
- spec/dummy/config/environments/production.rb
|
176
|
+
- spec/dummy/config/locales/en.yml
|
177
|
+
- spec/dummy/bin/rake
|
178
|
+
- spec/dummy/bin/bundle
|
179
|
+
- spec/dummy/bin/setup
|
180
|
+
- spec/dummy/bin/rails
|
181
|
+
- spec/dummy/db/schema.rb
|
182
|
+
- spec/dummy/db/development.sqlite3
|
183
|
+
- spec/dummy/db/test.sqlite3
|
184
|
+
- spec/dummy/db/migrate/20150204045322_create_users.rb
|
185
|
+
- spec/dummy/app/helpers/application_helper.rb
|
186
|
+
- spec/dummy/app/models/user.rb
|
187
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
188
|
+
- spec/dummy/app/controllers/application_controller.rb
|
189
|
+
- spec/dummy/app/assets/stylesheets/application.css
|
190
|
+
- spec/dummy/app/assets/javascripts/application.js
|
191
|
+
- spec/dummy/Rakefile
|
192
|
+
- spec/dummy/README.rdoc
|
193
|
+
- spec/models/user_spec.rb
|
194
|
+
- spec/views/users_routes_spec.rb
|
116
195
|
- spec/spec_helper.rb
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/README.md
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
# HashIds
|
2
|
-
|
3
|
-
Obfuscate your id in the air
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'hash_ids'
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install hash_ids
|
20
|
-
|
21
|
-
## Usage
|
22
|
-
|
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
|
-
|
53
|
-
|
54
|
-
## Contributing
|
55
|
-
|
56
|
-
1. Fork it ( https://github.com/[my-github-username]/hash_ids/fork )
|
57
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
-
5. Create a new Pull Request
|
data/hash_ids.gemspec
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'hash_ids/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "hash_ids"
|
8
|
-
spec.version = HashIds::VERSION
|
9
|
-
spec.authors = ["kemingcao"]
|
10
|
-
spec.email = ["keming.cao@gmail.com"]
|
11
|
-
spec.summary = %q{Obfuscate id like a foodie.}
|
12
|
-
spec.description = %q{Obfuscate id on your record.}
|
13
|
-
spec.homepage = "https://github.com/kemingcao/hash_ids"
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_dependency 'hashids', '~> 1.0'
|
22
|
-
spec.add_development_dependency "bundler", "~> 1.7"
|
23
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
-
end
|
data/spec/hash_ids_spec.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
class Foodie < ActiveRecord::Base
|
4
|
-
extend HashIds
|
5
|
-
hash_as_id
|
6
|
-
|
7
|
-
attr_reader :id
|
8
|
-
def id
|
9
|
-
@id ||= Random.new.rand 10000
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe HashIds do
|
14
|
-
|
15
|
-
it 'has a version number' do
|
16
|
-
expect(HashIds::VERSION).not_to be nil
|
17
|
-
end
|
18
|
-
|
19
|
-
before :all do
|
20
|
-
@chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
|
21
|
-
|
22
|
-
@salt = @chars.split('').sample(10).join('')
|
23
|
-
@min_hash_length = Random.new.rand 2...20
|
24
|
-
@alphabet = @chars.split('').sample(18).join('')
|
25
|
-
|
26
|
-
HashIds.config do |c|
|
27
|
-
c.salt = @salt
|
28
|
-
c.min_hash_length = @min_hash_length
|
29
|
-
c.alphabet = @alphabet
|
30
|
-
end
|
31
|
-
|
32
|
-
@foodie = Foodie.new
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
describe 'HashIds config and hasher' do
|
37
|
-
it 'test config' do
|
38
|
-
expect(HashIds.config.salt).to eq @salt
|
39
|
-
expect(HashIds.config.min_hash_length).to eq @min_hash_length
|
40
|
-
expect(HashIds.config.alphabet).to eq @alphabet
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'test hasher' do
|
44
|
-
expect(HashIds.hasher).not_to be nil
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe 'test hasher' do
|
49
|
-
it 'to_parmas' do
|
50
|
-
expect(@foodie.to_param).not_to be nil
|
51
|
-
expect(@foodie.to_param).to eq @foodie.hash_ids_encode(@foodie.id)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|