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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 4867c4d589558084a2562c78eb9266aa2f1f43d7cc1f1acd8eefa54b8c710591
4
- data.tar.gz: d79b8524b69862073197a4e92ff53cbb25f88870872c01c998bc59122b9893e9
2
+ SHA1:
3
+ metadata.gz: 9a9b1cf5f69f89d643ee428146783e7f597303f1
4
+ data.tar.gz: d7a50b7c3bbd49afbc29a3953b862a7a4e348315
5
5
  SHA512:
6
- metadata.gz: 5a41b9db0b8a08fc43d1f790ed3774da4199a47f33737494551595e8600316eb0d87a03f7b61fa1f2ec41c6c8b309ba8b50e175b757269c172c1204ead418bd6
7
- data.tar.gz: 13628fa0da1d14c55c01c6e62a94762f9b0170d22fa6dfaf5c591633b56c5f118d89a818550a18f9ade97a4bdd2d31241fb6b2f1dfb7d84883a5590fde3b15d6
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
- # Ketsuban
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 -> next_id { next_id.odd? }
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).
@@ -1,5 +1,6 @@
1
1
  require_relative './adapters/postgresql_adapter'
2
2
  require_relative './adapters/mysql2_adapter'
3
+ require_relative './adapters/sqlite_adapter'
3
4
 
4
5
  module Ketsuban
5
6
  module Adapter
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Ketsuban
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
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.2.1
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-15 00:00:00.000000000 Z
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.7.6
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