ketsuban 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +11 -9
- data/lib/ketsuban/adapter.rb +1 -0
- data/lib/ketsuban/adapters/sqlite_adapter.rb +27 -0
- data/lib/ketsuban/version.rb +1 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9a9b1cf5f69f89d643ee428146783e7f597303f1
|
4
|
+
data.tar.gz: d7a50b7c3bbd49afbc29a3953b862a7a4e348315
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ceda15de5b6bc475e25e93322f3f2480b2432e397b32a04faa0f6a8710ee1ccbf38e8ef44e47b6a3963a8d94cf7acc4e1e0d8e6353e7ed38e26f76c377c445b
|
7
|
+
data.tar.gz: d9aa66e54634948a44406b4790d8cbc6ed6c8d814e6a4c5a660fda6254c4cb4bb5c0081605b3e186297841a9002a93f58ad2d008bb6ab1f67263d335804a6b06
|
data/README.md
CHANGED
@@ -1,12 +1,20 @@
|
|
1
1
|
[![https://badge.fury.io/rb/ketsuban.svg](https://badge.fury.io/rb/ketsuban.svg)](https://rubygems.org/gems/ketsuban)
|
2
2
|
[![Build Status](https://travis-ci.org/oieioi/ketsuban.svg?branch=master)](https://travis-ci.org/oieioi/ketsuban)
|
3
3
|
|
4
|
-
#
|
4
|
+
# ketsuban
|
5
5
|
|
6
|
-
Skip unlucky numbers for ActiveRecord surrogate key
|
6
|
+
Skip unlucky numbers for ActiveRecord surrogate key `id`.
|
7
7
|
|
8
8
|
## Usage
|
9
9
|
|
10
|
+
Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'ketsuban'
|
14
|
+
```
|
15
|
+
|
16
|
+
Some Model:
|
17
|
+
|
10
18
|
```ruby
|
11
19
|
class User < ApplicationRecord
|
12
20
|
include Ketsuban
|
@@ -22,19 +30,13 @@ or
|
|
22
30
|
```ruby
|
23
31
|
class User < ApplicationRecord
|
24
32
|
include Ketsuban
|
25
|
-
unlucky_numbers ->
|
33
|
+
unlucky_numbers ->(next_id) { next_id.odd? }
|
26
34
|
end
|
27
35
|
|
28
36
|
5.times.map { User.create.id }
|
29
37
|
# => [2, 4, 6, 8, 10]
|
30
38
|
```
|
31
39
|
|
32
|
-
|
33
|
-
|
34
|
-
## TODO
|
35
|
-
|
36
|
-
- Support sqlite3
|
37
|
-
|
38
40
|
## License
|
39
41
|
|
40
42
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/ketsuban/adapter.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative './abstract_adapter'
|
2
|
+
|
3
|
+
module Ketsuban
|
4
|
+
module Adapter
|
5
|
+
class SQLiteAdapter < AbstractAdapter
|
6
|
+
# @override
|
7
|
+
def fetch_next_id
|
8
|
+
last_value_result = @model_class
|
9
|
+
.connection
|
10
|
+
.execute("select seq from sqlite_sequence where name = '#{@model_class.table_name}'")
|
11
|
+
.first
|
12
|
+
|
13
|
+
if last_value_result
|
14
|
+
last_value_result["seq"] + 1
|
15
|
+
else
|
16
|
+
1
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# @override
|
21
|
+
def increment_sequence(_now_id)
|
22
|
+
# do nothing
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/ketsuban/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ketsuban
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- oieioi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sqlite3
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.3.6
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.3.6
|
97
111
|
description: Skip unlucky numbers for ActiveRecord surrogate key
|
98
112
|
email:
|
99
113
|
- atsuinatsu.samuifuyu@gmail.com
|
@@ -109,6 +123,7 @@ files:
|
|
109
123
|
- lib/ketsuban/adapters/abstract_adapter.rb
|
110
124
|
- lib/ketsuban/adapters/mysql2_adapter.rb
|
111
125
|
- lib/ketsuban/adapters/postgresql_adapter.rb
|
126
|
+
- lib/ketsuban/adapters/sqlite_adapter.rb
|
112
127
|
- lib/ketsuban/base.rb
|
113
128
|
- lib/ketsuban/railtie.rb
|
114
129
|
- lib/ketsuban/utils.rb
|
@@ -134,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
149
|
version: '0'
|
135
150
|
requirements: []
|
136
151
|
rubyforge_project:
|
137
|
-
rubygems_version: 2.
|
152
|
+
rubygems_version: 2.6.14
|
138
153
|
signing_key:
|
139
154
|
specification_version: 4
|
140
155
|
summary: Skip unlucky numbers for ActiveRecord surrogate key
|