sequel-hash_id 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sequel/plugins/hash_id.rb +15 -12
  3. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0fda23b727eff09bf0c2047993946945ba8999f
4
- data.tar.gz: 9ee99e696a6960f612ce546ff3d46731b7724f02
3
+ metadata.gz: aafa0a0c8204caf2183098e22984dff496167ef4
4
+ data.tar.gz: 61707eaf7e0adb2365c4f6d3114c32816bb1245d
5
5
  SHA512:
6
- metadata.gz: 90cf852bcca48f78ecaffe374e91e54756e87f2592ef304a30f9c750610f417213aa1c91d7ca35350f29aa4b1a814ee5897331fba884503fe110d108231c95a0
7
- data.tar.gz: ab19e431be943c905c83cf59582a6f1d28cc08b21df026529daf4fad7b4bbb54b9c2acbdcd56a24abb2182220484118fe8fda198cbba23529837e1bfc2b8568a
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
- self.class.hasher.encode(id) if id
40
+ model.hasher.encode(id) if id
49
41
  end
50
42
  end
51
43
 
52
44
  module DatasetMethods
53
- extend Forwardable
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
- def_delegators :model, :with_hashid
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.0
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-02-10 00:00:00.000000000 Z
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: []