hashid-rails 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +10 -0
- data/CHANGELOG.md +3 -0
- data/README.md +1 -1
- data/hashid-rails.gemspec +2 -2
- data/lib/hashid/rails.rb +25 -4
- data/lib/hashid/rails/version.rb +1 -1
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57c692d5064faea88ae4b6f088c69bdbfd0ab54e
|
4
|
+
data.tar.gz: ec1b561f21d8550635dd082c584105c48c19e49c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e021ef31cedc780f17346d4eb282ea318ed572c09dd15577b2158e2668d9042f0dadb8ad5f371507b706a4a4b7324168d462c13cd06f326db844d49dbadc7a42
|
7
|
+
data.tar.gz: 4a9fd16a4baa41f920e58d8d26652b35e3daab18899849f2613cfda7cf22cb5f5c33f645d671af1097d2ae34ed225373757307666f24faa95871cf662b4794cd
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Hashid Rails
|
2
|
-
[
|
2
|
+
[![Build Status](https://travis-ci.org/jcypret/hashid-rails.svg?branch=master)](https://travis-ci.org/jcypret/hashid-rails)
|
3
3
|
[![Code Climate](https://codeclimate.com/github/jcypret/hashid-rails/badges/gpa.svg)](https://codeclimate.com/github/jcypret/hashid-rails)
|
4
4
|
[![Test Coverage](https://codeclimate.com/github/jcypret/hashid-rails/badges/coverage.svg)](https://codeclimate.com/github/jcypret/hashid-rails/coverage)
|
5
5
|
|
data/hashid-rails.gemspec
CHANGED
@@ -25,8 +25,8 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
26
|
spec.require_paths = ['lib']
|
27
27
|
|
28
|
-
spec.add_development_dependency 'bundler'
|
29
|
-
spec.add_development_dependency 'rake'
|
28
|
+
spec.add_development_dependency 'bundler'
|
29
|
+
spec.add_development_dependency 'rake'
|
30
30
|
spec.add_development_dependency 'rspec', '~> 3.4.0'
|
31
31
|
|
32
32
|
spec.add_runtime_dependency 'activerecord', '>= 4.0'
|
data/lib/hashid/rails.rb
CHANGED
@@ -46,23 +46,44 @@ module Hashid
|
|
46
46
|
Hashids.new(*arguments)
|
47
47
|
end
|
48
48
|
|
49
|
-
def encode_id(
|
50
|
-
|
49
|
+
def encode_id(ids)
|
50
|
+
if ids.is_a?(Array)
|
51
|
+
ids.map { |id| hashid_encode(id) }
|
52
|
+
else
|
53
|
+
hashid_encode(ids)
|
54
|
+
end
|
51
55
|
end
|
52
56
|
|
53
|
-
def decode_id(
|
54
|
-
|
57
|
+
def decode_id(ids)
|
58
|
+
if ids.is_a?(Array)
|
59
|
+
ids.map { |id| hashid_decode(id) }
|
60
|
+
else
|
61
|
+
hashid_decode(ids)
|
62
|
+
end
|
55
63
|
end
|
56
64
|
|
57
65
|
def find(hashid)
|
58
66
|
model_reload? ? super(hashid) : super( decode_id(hashid) || hashid )
|
59
67
|
end
|
60
68
|
|
69
|
+
# Calls `find` with decoded hashid
|
70
|
+
def find_by_hashid(hashid)
|
71
|
+
find_by!(id: hashid_decode(hashid))
|
72
|
+
end
|
73
|
+
|
61
74
|
private
|
62
75
|
|
63
76
|
def model_reload?
|
64
77
|
caller.any? {|s| s =~ /active_record\/persistence.*reload/}
|
65
78
|
end
|
79
|
+
|
80
|
+
def hashid_decode(id)
|
81
|
+
hashids.decode(id.to_s).first
|
82
|
+
end
|
83
|
+
|
84
|
+
def hashid_encode(id)
|
85
|
+
hashids.encode(id)
|
86
|
+
end
|
66
87
|
end
|
67
88
|
|
68
89
|
class Configuration
|
data/lib/hashid/rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashid-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Cypret
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
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: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
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: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +94,7 @@ extra_rdoc_files: []
|
|
94
94
|
files:
|
95
95
|
- ".gitignore"
|
96
96
|
- ".rspec"
|
97
|
+
- ".travis.yml"
|
97
98
|
- CHANGELOG.md
|
98
99
|
- Gemfile
|
99
100
|
- LICENSE.txt
|