randomize_id 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b139d0e12db9e2c48483c8416908b4eaf7431c1905cbb833dcb1543fa81a94da
4
+ data.tar.gz: 01fb47cc682aa62ee475d9943486ec6d06e123311943f073a0ca23e6494a41be
5
+ SHA512:
6
+ metadata.gz: 7c97112a68d9ac13982d20079101512275d226d97aef5e62659dc62cfef2cf95bf037fe95f0ac404c842f838e19ded9a98c3c4e59ab195f1fb8c76a47dcc4b06
7
+ data.tar.gz: 2bc979996ef885d8dcde4c0f40c74cf98c52aaa9c42fb4c648cce7117a52018fc38fc9e723fcdb5b8b6fdc9e877efd791f21ed7bfa21f0aed9774084516d2492
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ### master
4
+
5
+ * nothing yet
6
+
7
+ ### 1.0.0 - 2018/01/20
8
+
9
+ * initial release
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Jonas Hübotter
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,124 @@
1
+ # RandomizeId
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/randomize_id.svg)](https://badge.fury.io/rb/randomize_id) <img src="https://travis-ci.org/jonhue/randomize_id.svg?branch=master" />
4
+
5
+ Randomize the `id` attribute of ActiveRecord objects.
6
+
7
+ ---
8
+
9
+ ## Table of Contents
10
+
11
+ * [Installation](#installation)
12
+ * [Usage](#usage)
13
+ * [Layouts](#layouts)
14
+ * [Components](#components)
15
+ * [Configuration](#configuration)
16
+ * [To Do](#to-do)
17
+ * [Contributing](#contributing)
18
+ * [Contributors](#contributors)
19
+ * [Semantic versioning](#semantic-versioning)
20
+ * [License](#license)
21
+
22
+ ---
23
+
24
+ ## Installation
25
+
26
+ RandomizeId works with Rails 5 onwards. You can add it to your `Gemfile` with:
27
+
28
+ ```ruby
29
+ gem 'randomize_id'
30
+ ```
31
+
32
+ And then execute:
33
+
34
+ $ bundle
35
+
36
+ Or install it yourself as:
37
+
38
+ $ gem install randomize_id
39
+
40
+ If you always want to be up to date fetch the latest from GitHub in your `Gemfile`:
41
+
42
+ ```ruby
43
+ gem 'randomize_id', github: 'jonhue/randomize_id'
44
+ ```
45
+
46
+ Now run the generator:
47
+
48
+ $ rails g randomize_id
49
+
50
+ ---
51
+
52
+ ## Usage
53
+
54
+ Unless you [configured](#configuration) RandomizeId to automatically randomize IDs for all ActiveRecord objects, you have to add the following to every model whose records should have random Ids:
55
+
56
+ ```ruby
57
+ include RandomizeId
58
+ ```
59
+
60
+ That's it!
61
+
62
+ ---
63
+
64
+ ## Configuration
65
+
66
+ You can configure RandomizeId by passing a block to `configure`. This can be done in `config/initializers/randomize_id.rb`:
67
+
68
+ ```ruby
69
+ RandomizeId.configure do |config|
70
+ config.auto = false
71
+ end
72
+ ```
73
+
74
+ * `auto` Automaitcally randomize IDs of all ActiveRecord objects. Takes a boolean. Defaults to `false`.
75
+
76
+ ---
77
+
78
+ ## To Do
79
+
80
+ [Here](https://github.com/jonhue/randomize_id/projects/1) is the full list of current projects.
81
+
82
+ To propose your ideas, initiate the discussion by adding a [new issue](https://github.com/jonhue/randomize_id/issues/new).
83
+
84
+ ---
85
+
86
+ ## Contributing
87
+
88
+ We hope that you will consider contributing to RandomizeId. Please read this short overview for some information about how to get started:
89
+
90
+ [Learn more about contributing to this repository](CONTRIBUTING.md), [Code of Conduct](CODE_OF_CONDUCT.md)
91
+
92
+ ### Contributors
93
+
94
+ Give the people some :heart: who are working on this project. See them all at:
95
+
96
+ https://github.com/jonhue/randomize_id/graphs/contributors
97
+
98
+ ### Semantic Versioning
99
+
100
+ RandomizeId follows Semantic Versioning 2.0 as defined at http://semver.org.
101
+
102
+ ## License
103
+
104
+ MIT License
105
+
106
+ Copyright (c) 2018 Jonas Hübotter
107
+
108
+ Permission is hereby granted, free of charge, to any person obtaining a copy
109
+ of this software and associated documentation files (the "Software"), to deal
110
+ in the Software without restriction, including without limitation the rights
111
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
112
+ copies of the Software, and to permit persons to whom the Software is
113
+ furnished to do so, subject to the following conditions:
114
+
115
+ The above copyright notice and this permission notice shall be included in all
116
+ copies or substantial portions of the Software.
117
+
118
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
119
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
120
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
121
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
122
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
123
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
124
+ SOFTWARE.
@@ -0,0 +1,17 @@
1
+ module RandomizeId
2
+
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_create :randomize_id
7
+ end
8
+
9
+ private
10
+
11
+ def randomize_id
12
+ begin
13
+ self.id = SecureRandom.random_number 9_223_372_036_854_775_807
14
+ end while self.class.where(id: self.id).exists?
15
+ end
16
+
17
+ end
@@ -0,0 +1,15 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ class RandomizeIdGenerator < Rails::Generators::Base
5
+
6
+ include Rails::Generators::Migration
7
+
8
+ source_root File.join File.dirname(__FILE__), 'templates'
9
+ desc 'Install RandomizeId'
10
+
11
+ def create_initializer
12
+ template 'initializer.rb', 'config/initializers/randomize_id.rb'
13
+ end
14
+
15
+ end
@@ -0,0 +1,6 @@
1
+ RandomizeId.configure do |config|
2
+
3
+ # Automaitcally randomize IDs of all ActiveRecord objects
4
+ # config.auto = false
5
+
6
+ end
@@ -0,0 +1,10 @@
1
+ require 'randomize_id/version'
2
+
3
+ module RandomizeId
4
+
5
+ require 'randomize_id/configuration'
6
+
7
+ require 'randomize_id/engine'
8
+ require 'randomize_id/railtie'
9
+
10
+ end
@@ -0,0 +1,21 @@
1
+ module RandomizeId
2
+
3
+ class << self
4
+ attr_accessor :configuration
5
+ end
6
+
7
+ def self.configure
8
+ self.configuration ||= Configuration.new
9
+ yield configuration
10
+ end
11
+
12
+ class Configuration
13
+
14
+ attr_accessor :auto
15
+
16
+ def initialize
17
+ @auto = false
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,6 @@
1
+ require 'rails/railtie'
2
+
3
+ module RandomizeId
4
+ class Engine < Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails/railtie'
2
+
3
+ module RandomizeId
4
+ class Railtie < Rails::Railtie
5
+
6
+ initializer 'randomize_id.initialize' do
7
+ ActiveSupport.on_load :active_record do
8
+ include RandomizeId if RandomizeId.configuration&.auto
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module RandomizeId
2
+
3
+ VERSION = '1.0.0'
4
+
5
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: randomize_id
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonas Hübotter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activerecord
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.52'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.52'
83
+ description: Randomize the `id` attribute of ActiveRecord objects.
84
+ email: me@jonhue.me
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - CHANGELOG.md
90
+ - LICENSE
91
+ - README.md
92
+ - app/models/concerns/randomize_id.rb
93
+ - lib/generators/randomize_id_generator.rb
94
+ - lib/generators/templates/initializer.rb
95
+ - lib/randomize_id.rb
96
+ - lib/randomize_id/configuration.rb
97
+ - lib/randomize_id/engine.rb
98
+ - lib/randomize_id/railtie.rb
99
+ - lib/randomize_id/version.rb
100
+ homepage: https://github.com/jonhue/randomize_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: '2.3'
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.4
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Randomize ActiveRecord IDs
124
+ test_files: []