acts_as_hashids 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gemrelease +2 -0
- data/README.md +17 -1
- data/acts_as_hashids.gemspec +2 -2
- data/lib/acts_as_hashids/core.rb +11 -1
- data/lib/acts_as_hashids/version.rb +1 -1
- data/spec/acts_as_hashids/core_spec.rb +3 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 566fc3dc46c7d62d6b380440acc8f5b58a168be0
|
4
|
+
data.tar.gz: bd082d7e564dad63be19230dd89c5662b111d1b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 359269409ec054b38093f527a6b57b2b0ee6bae5103828e40d14504a897901e4eb72f42b2e486350ebd352500c79f83603bc611ec2fa41155c30b341bcc5880c
|
7
|
+
data.tar.gz: 89b03a0959d3bd501b047d1d42cd0110d3419420116936fe31a58f5023d7be6f2341e93fa32341adcbf3b658fc77ad4399977ae1c384d5fed7e9cbaa772e54c9
|
data/.gemrelease
ADDED
data/README.md
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
# acts_as_hashids
|
2
2
|
|
3
3
|
[![Gem Version][gem-image]][gem-link]
|
4
|
+
[![Download][download-image]][download-link]
|
4
5
|
[![Build Status][build-image]][build-link]
|
5
6
|
[![Coverage Status][cov-image]][cov-link]
|
6
7
|
[![Code Climate][gpa-image]][gpa-link]
|
7
8
|
|
8
|
-
Use [Hashids](https://github.com/peterhellberg/hashids.rb) (a.k.a. Youtube-Like ID) in ActiveRecord
|
9
|
+
Use [Hashids](https://github.com/peterhellberg/hashids.rb) (a.k.a. Youtube-Like ID) in ActiveRecord seamlessly.
|
9
10
|
|
10
11
|
## Installation
|
11
12
|
|
@@ -81,6 +82,19 @@ Foo2.create.to_param
|
|
81
82
|
# => "RxQce3a2"
|
82
83
|
```
|
83
84
|
|
85
|
+
### alphabet
|
86
|
+
|
87
|
+
Specify which characters you use to generate hashids.
|
88
|
+
|
89
|
+
```rb
|
90
|
+
class Foo < ActiveRecord::Base
|
91
|
+
acts_as_hashids alphabet: '0123456789uvwxyz'
|
92
|
+
end
|
93
|
+
|
94
|
+
Foo3.create(id: 1).to_param
|
95
|
+
# => "4xw8zwyv"
|
96
|
+
```
|
97
|
+
|
84
98
|
## Test
|
85
99
|
|
86
100
|
Execute the command below to run rspec and rubocop.
|
@@ -106,6 +120,8 @@ Copyright (c) 2014 Daisuke Taniwaki. See [LICENSE](LICENSE) for details.
|
|
106
120
|
|
107
121
|
[gem-image]: https://badge.fury.io/rb/acts_as_hashids.svg
|
108
122
|
[gem-link]: http://badge.fury.io/rb/acts_as_hashids
|
123
|
+
[download-image]:https://img.shields.io/gem/dt/acts_as_hashids.svg
|
124
|
+
[download-link]:https://rubygems.org/gems/acts_as_hashids
|
109
125
|
[build-image]: https://secure.travis-ci.org/dtaniwaki/acts_as_hashids.png
|
110
126
|
[build-link]: http://travis-ci.org/dtaniwaki/acts_as_hashids
|
111
127
|
[cov-image]: https://coveralls.io/repos/dtaniwaki/acts_as_hashids/badge.png
|
data/acts_as_hashids.gemspec
CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.authors = ['dtaniwaki']
|
11
11
|
spec.email = ['daisuketaniwaki@gmail.com']
|
12
12
|
|
13
|
-
spec.summary = '
|
14
|
-
spec.description = 'Use
|
13
|
+
spec.summary = 'Use Youtube-Like ID in ActiveRecord seamlessly.'
|
14
|
+
spec.description = 'Use Youtube-Like ID in ActiveRecord seamlessly.'
|
15
15
|
spec.homepage = 'https://github.com/dtaniwaki/acts_as_hashids'
|
16
16
|
spec.license = 'MIT'
|
17
17
|
|
data/lib/acts_as_hashids/core.rb
CHANGED
@@ -13,7 +13,17 @@ module ActsAsHashids
|
|
13
13
|
def find(ids = nil, &block)
|
14
14
|
return detect(&block) if block.present? && respond_to?(:detect)
|
15
15
|
|
16
|
-
encoded_ids = Array(ids).map
|
16
|
+
encoded_ids = Array(ids).map do |id|
|
17
|
+
begin
|
18
|
+
id = id.to_i if Float(id)
|
19
|
+
hashids.encode(id)
|
20
|
+
rescue TypeError, ArgumentError
|
21
|
+
id
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
encoded_ids = encoded_ids.flatten
|
26
|
+
|
17
27
|
res = with_hashids(encoded_ids).all
|
18
28
|
if ids.is_a?(Array)
|
19
29
|
raise_record_not_found_exception! encoded_ids, res.size, encoded_ids.size if res.size != encoded_ids.size
|
@@ -45,6 +45,9 @@ RSpec.describe ActsAsHashids::Core do
|
|
45
45
|
)
|
46
46
|
end
|
47
47
|
end
|
48
|
+
it 'returns the record when finding by string id' do
|
49
|
+
expect(subject.find(foo1.id.to_s)).to eq foo1
|
50
|
+
end
|
48
51
|
end
|
49
52
|
context 'for multiple arguments' do
|
50
53
|
it 'decodes hash id and returns the record' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_hashids
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dtaniwaki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashids
|
@@ -156,7 +156,7 @@ dependencies:
|
|
156
156
|
- - "~>"
|
157
157
|
- !ruby/object:Gem::Version
|
158
158
|
version: '0.5'
|
159
|
-
description: Use
|
159
|
+
description: Use Youtube-Like ID in ActiveRecord seamlessly.
|
160
160
|
email:
|
161
161
|
- daisuketaniwaki@gmail.com
|
162
162
|
executables:
|
@@ -165,6 +165,7 @@ executables:
|
|
165
165
|
extensions: []
|
166
166
|
extra_rdoc_files: []
|
167
167
|
files:
|
168
|
+
- ".gemrelease"
|
168
169
|
- ".gitignore"
|
169
170
|
- ".rspec"
|
170
171
|
- ".rubocop.yml"
|
@@ -211,7 +212,7 @@ rubyforge_project:
|
|
211
212
|
rubygems_version: 2.6.8
|
212
213
|
signing_key:
|
213
214
|
specification_version: 4
|
214
|
-
summary:
|
215
|
+
summary: Use Youtube-Like ID in ActiveRecord seamlessly.
|
215
216
|
test_files:
|
216
217
|
- spec/acts_as_hashids/core_spec.rb
|
217
218
|
- spec/acts_as_hashids/methods_spec.rb
|