sequel-nonsequential_id 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4092f9d8947383ae099eb15b1bb5e48b3eb572f56460c3db5545a45c4c9adff8
4
+ data.tar.gz: 88a9a676917bb0bc20fc890eb61d7491c8e6b88fe2a89638e9aa72e008c53aae
5
+ SHA512:
6
+ metadata.gz: 0e2f63c596303c7a28df3f6c0af2fd7802b2234a6c7c65415d5e0091687e62a2aec14c635ffe922b1d75ee6ced4810b449d18f4b94b66328197e790e1f22e86b
7
+ data.tar.gz: 54f4ef3d3957f7563c794b84e27444a31b14b21338816fd274cb7bc2b8a6e8a0911704843ec4cc355e7cb6a436460708d71edf5b1f7f32f47d6119ce7959e14f
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+
16
+ *.iml
17
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Dashing Rocket, Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # sequel-nonsequential_id
2
+ [![Run Status](https://api.shippable.com/projects/5bb3aa2628d5f40700431d28/badge?branch=master)](https://app.shippable.com/github/dashingrocket/sequel-nonsequential_id/dashboard)
3
+ [![Gem Version](https://badge.fury.io/rb/sequel-nonsequential_id.svg)](http://badge.fury.io/rb/sequel-nonsequential_id)
4
+ [![Downloads](http://ruby-gem-downloads-badge.herokuapp.com/sequel-nonsequential_id?type=total)](https://rubygems.org/gems/sequel-nonsequential_id)
5
+
6
+ Automatically generate non-sequential (pseudo-random) IDs for Sequel Models
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'sequel-nonsequential_id'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install sequel-nonsequential_id
23
+
24
+ ## Usage
25
+
26
+ ```ruby
27
+ # Enable nonsequential id for all Models
28
+ Sequel::Model.plugin :nonsequential_id
29
+
30
+ # Enable nonsequential id on a specific model (defaults to the :id field)
31
+ class Artist < Sequel::Model
32
+ plugin :nonsequential_id
33
+ end
34
+
35
+
36
+ # Enable nonsequential id on a specific model using a custom id field
37
+ class Artist < Sequel::Model
38
+ plugin :nonsequential_id, id_field: :custom_id_field
39
+ end
40
+ ```
41
+
42
+ ## Continuous Integration
43
+ Tested in a CI environment against the following Ruby versions:
44
+ * ruby-head
45
+ * 2.5
46
+ * 2.4
47
+ * 2.3
48
+
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it ( https://github.com/dashingrocket/sequel-nonsequential_id/fork )
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create a new Pull Request
57
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.test_files = FileList['test/*_test.rb']
7
+ end
8
+
9
+ desc 'Run tests'
10
+ task :default => [:test]
@@ -0,0 +1,37 @@
1
+ require 'securerandom'
2
+
3
+ module Sequel
4
+ module Plugins
5
+ module NonsequentialId
6
+ def self.configure(model, opts = {})
7
+ model.instance_eval do
8
+ @id_field = opts[:id_field] || :id
9
+ end
10
+ end
11
+
12
+ module ClassMethods
13
+ attr_reader :id_field
14
+ Sequel::Plugins.inherited_instance_variables(self, :@id_field => nil)
15
+ end
16
+
17
+ module InstanceMethods
18
+ def before_create
19
+ set_nonsequential_id
20
+ super
21
+ end
22
+
23
+ private def set_nonsequential_id
24
+ method = :"#{model.id_field}="
25
+
26
+ loop do
27
+ id = SecureRandom.hex.hex.to_s(36)
28
+ unless model.first("#{model.id_field}": id)
29
+ set_column_value(method, id)
30
+ return id
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'sequel-nonsequential_id'
5
+ spec.version = '0.1.0'
6
+ spec.authors = ['Jesse Bowes']
7
+ spec.email = ['jbowes@dashingrocket.com']
8
+ spec.summary = 'Sequel Non-Sequential Unique ID Plugin'
9
+ spec.description = 'Automatically generate non-sequential (pseudo-random) IDs for Sequel Models'
10
+ spec.homepage = 'https://github.com/dashingrocket/sequel-nonsequential_id'
11
+ spec.license = 'MIT'
12
+
13
+ spec.files = `git ls-files -z`.split("\x0")
14
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.require_paths = ['lib']
17
+
18
+ spec.add_dependency 'sequel', '~> 5.13'
19
+
20
+ spec.add_development_dependency 'test-unit', '~> 3.2'
21
+ spec.add_development_dependency 'bundler', '~> 1.16'
22
+ spec.add_development_dependency 'rake', '~> 12.0'
23
+ spec.add_development_dependency 'sqlite3', '~> 1.3'
24
+ end
data/shippable.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - ruby-head
5
+ - 2.5
6
+ - 2.4
7
+ - 2.3
@@ -0,0 +1,62 @@
1
+ require 'test/unit'
2
+ require 'sequel'
3
+
4
+ require_relative '../lib/sequel/plugins/nonsequential_id'
5
+
6
+ DB = Sequel.sqlite
7
+
8
+ DB.create_table :test_models do
9
+ primary_key :id, type: String, auto_increment: false
10
+ String :name
11
+ end
12
+
13
+ DB.create_table :test_model2s do
14
+ primary_key :custom_id, type: String, auto_increment: false
15
+ String :name
16
+ end
17
+
18
+ class TestModel < Sequel::Model
19
+ plugin :nonsequential_id
20
+ end
21
+
22
+ class TestModel2 < Sequel::Model
23
+ plugin :nonsequential_id, id_field: :custom_id
24
+ end
25
+
26
+ class NonsequentialIdTest < Test::Unit::TestCase
27
+ def setup
28
+
29
+ end
30
+
31
+ def test_nonsequential_id
32
+ obj1 = TestModel.create(name: 'obj1')
33
+ obj2 = TestModel.create(name: 'obj2')
34
+
35
+ assert_kind_of String, obj1.id
36
+ assert_kind_of String, obj2.id
37
+
38
+ assert_not_empty obj1.id
39
+ assert_not_empty obj2.id
40
+
41
+ assert_not_equal obj1.id, obj2.id
42
+
43
+ assert_equal(obj1.id, TestModel.first(id: obj1.id).id)
44
+ assert_equal(obj2.id, TestModel.first(id: obj2.id).id)
45
+ end
46
+
47
+ def test_test_nonsequential_id_custom_field
48
+ obj1 = TestModel2.create(name: 'obj1')
49
+ obj2 = TestModel2.create(name: 'obj2')
50
+
51
+ assert_kind_of String, obj1.custom_id
52
+ assert_kind_of String, obj2.custom_id
53
+
54
+ assert_not_empty obj1.custom_id
55
+ assert_not_empty obj2.custom_id
56
+
57
+ assert_not_equal obj1.custom_id, obj2.custom_id
58
+
59
+ assert_equal(obj1.custom_id, TestModel2.first(custom_id: obj1.custom_id).custom_id)
60
+ assert_equal(obj2.custom_id, TestModel2.first(custom_id: obj2.custom_id).custom_id)
61
+ end
62
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sequel-nonsequential_id
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jesse Bowes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sequel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.13'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: test-unit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ description: Automatically generate non-sequential (pseudo-random) IDs for Sequel
84
+ Models
85
+ email:
86
+ - jbowes@dashingrocket.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE
94
+ - README.md
95
+ - Rakefile
96
+ - lib/sequel/plugins/nonsequential_id.rb
97
+ - sequel-unique_id.gemspec
98
+ - shippable.yml
99
+ - test/nonsequential_id_test.rb
100
+ homepage: https://github.com/dashingrocket/sequel-nonsequential_id
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.7.6
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Sequel Non-Sequential Unique ID Plugin
124
+ test_files:
125
+ - test/nonsequential_id_test.rb