sequel-hash_id 0.1.0 → 0.1.1
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 +4 -4
- data/lib/sequel/plugins/hash_id.rb +15 -12
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aafa0a0c8204caf2183098e22984dff496167ef4
|
4
|
+
data.tar.gz: 61707eaf7e0adb2365c4f6d3114c32816bb1245d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90432cade9237d62a40c1c4a814c993bb1e688aa354db976b76da478faa51b534b08d767bf1151e74f6b0cb70edb3d93c265927d030813a6db7039c7956b4c80
|
7
|
+
data.tar.gz: 9b8459c41772d2e2e41ab1484737cf5bceecc354bf5b03733b69200277ae1e3ad13e881c1fe859e3289cfc63263e8fb21215733d737c33fd3c66f00d0058ce08
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require "forwardable"
|
2
1
|
require "hashids"
|
3
2
|
|
4
3
|
module Sequel::Plugins # :nodoc:
|
@@ -27,32 +26,36 @@ module HashId
|
|
27
26
|
end
|
28
27
|
|
29
28
|
module ClassMethods
|
30
|
-
Sequel::Plugins.def_dataset_methods(self, :with_hashid)
|
29
|
+
Sequel::Plugins.def_dataset_methods(self, [:with_hashid, :with_hashid!])
|
31
30
|
|
32
31
|
# The instance of +Hashids+ used to encode and decode values
|
33
32
|
def hasher
|
34
33
|
Hashids.new(@hash_id_state[:salt], @hash_id_state[:length])
|
35
34
|
end
|
36
|
-
|
37
|
-
# Lookup a record with a hashid, returning nil if none is found
|
38
|
-
def with_hashid(hashid)
|
39
|
-
id ,= hasher.decode(hashid)
|
40
|
-
|
41
|
-
self[id] if id
|
42
|
-
end
|
43
35
|
end
|
44
36
|
|
45
37
|
module InstanceMethods
|
46
38
|
# The hashid of the model instance
|
47
39
|
def hashid
|
48
|
-
|
40
|
+
model.hasher.encode(id) if id
|
49
41
|
end
|
50
42
|
end
|
51
43
|
|
52
44
|
module DatasetMethods
|
53
|
-
|
45
|
+
# Lookup a record with a hashid, returning nil if none is found
|
46
|
+
def with_hashid(hashid)
|
47
|
+
id ,= model.hasher.decode(hashid)
|
48
|
+
|
49
|
+
self[id] if id
|
50
|
+
end
|
51
|
+
|
52
|
+
# Lookup a record with a hashid, raising +Sequel::NoMatchingError+
|
53
|
+
# if not found
|
54
|
+
def with_hashid!(hashid)
|
55
|
+
id ,= model.hasher.decode(hashid)
|
54
56
|
|
55
|
-
|
57
|
+
with_pk!(id)
|
58
|
+
end
|
56
59
|
end
|
57
60
|
end
|
58
61
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel-hash_id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Daniels
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sqlite3
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.3.13
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.3.13
|
83
97
|
description:
|
84
98
|
email: adam@mediadrive.ca
|
85
99
|
executables: []
|