track_ballast 0.1.0.beta4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +8 -0
- data/CONTRIBUTING.md +30 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +154 -0
- data/LICENSE.txt +13 -0
- data/README.md +84 -0
- data/Rakefile +8 -0
- data/bin/console +10 -0
- data/bin/setup +8 -0
- data/lib/track_ballast/all.rb +3 -0
- data/lib/track_ballast/callable.rb +41 -0
- data/lib/track_ballast/error.rb +5 -0
- data/lib/track_ballast/logger.rb +33 -0
- data/lib/track_ballast/uuid_management.rb +99 -0
- data/lib/track_ballast/version.rb +3 -0
- data/lib/track_ballast.rb +7 -0
- data/track_ballast.gemspec +41 -0
- metadata +246 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 887de32d1d460d9230a765425cf1b519d63f5c0abd8fce0e8fac3e90a643ccd7
|
4
|
+
data.tar.gz: ae81a4121ca6c294d6d663cc1240721094ab2d71a71f3030be5ff152356bd4fe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ad7eae3fe9ff99bfd661e83bafd37442117a7dad1cbd2cc9a7b848affbd59989e9d46e3360ea65544dc5cc1a18ffbc0111a25190ff54f237db89a00592404440
|
7
|
+
data.tar.gz: e97a831ca062da9e18d61f13a43526f19e129fd8b70d9e12ecdc35f48ab5c8ed914ad24bbf9c8a341d10b0722addf788473e033069d58cd8d3865839a92cb29e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.2
|
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Contributing to Doximity
|
2
|
+
|
3
|
+
We welcome contributions to this repository. Feel free to submit issues for bugs you encounter and pull requests for code and documentation contributions.
|
4
|
+
In order to prevent licensing issues, Doximity Inc. (“Doximity”, “we”, “us”) requires all contributors to agree to an Individual Contributor License Agreement (“CLA”), which is reproduced below. By submitting your contributions to us, you agree that you have read and are bound by the CLA. If you do not agree with the CLA, you may not submit contributions.
|
5
|
+
|
6
|
+
## Doximity Individual Contributor License Agreement
|
7
|
+
|
8
|
+
This license is for your protection as a Contributor as well as the protection of Doximity; it does not change your rights to use your own Contributions for any other purpose.
|
9
|
+
|
10
|
+
You accept and agree to the following terms and conditions for Your present and future Contributions submitted to Doximity. Except for the license granted herein to Doximity and recipients of software distributed by Doximity, You reserve all right, titles, and interests in and to Your Contributions.
|
11
|
+
|
12
|
+
### Definitions
|
13
|
+
|
14
|
+
"You" (or "Your" or the “Contributor”) shall mean the copyright owner or legal entity authorized by the copyright owner that is making this Agreement with Doximity. For legal entities, the entity making a Contribution and all other entities that control, are controlled by, or are under common control with that entity are considered to be a single Contributor. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
15
|
+
|
16
|
+
1. "Contribution" shall mean the code, documentation, or any original work of authorship, including any modifications or additions to an existing work, that is intentionally submitted by You to Doximity for inclusion in, or documentation of, any of the products owned or managed by Doximity (the "Work"). For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to Doximity or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, Doximity for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by You as "Not a Contribution."
|
17
|
+
|
18
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this Agreement, You hereby grant to Doximity and to recipients of software distributed by Doximity a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute Your Contributions and such derivative works.
|
19
|
+
|
20
|
+
3. Grant of Patent License. Subject to the terms and conditions of this Agreement, You hereby grant to Doximity and to recipients of software distributed by Doximity a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by You that are necessarily infringed by Your Contribution(s) alone or by a combination of Your Contribution(s) with the Work to which such Contribution(s) was submitted. If any entity institutes patent litigation against You or any other entity (including a cross-claim or counterclaim in a lawsuit) alleging that your Contribution, or the Work to which you have contributed, constitutes a direct or contributory patent infringement, then any patent licenses granted to that entity under this Agreement for that Contribution or Work shall terminate as of the date such litigation is filed.
|
21
|
+
|
22
|
+
4. You represent that You are legally entitled to grant the above license. If your employer(s) has rights to intellectual property that you create that includes your Contributions, you represent that you have received permission to make Contributions on behalf of that employer, that your employer has waived such rights for your Contributions to Doximity, or that your employer has executed a separate Corporate CLA with Doximity.
|
23
|
+
|
24
|
+
5. You represent that each of Your Contributions is Your original creation (see section 7 for submissions on behalf of others). You represent that Your Contribution submissions include complete details of any third-party license or other restriction (including, but not limited to, related patents and trademarks) of which you are personally aware and which are associated with any part of Your Contributions.
|
25
|
+
|
26
|
+
6. You are not expected to provide support for Your Contributions, except to the extent You desire to provide support. You may provide support for free, for a fee, or not at all. Unless required by applicable law or agreed to in writing, You provide Your Contributions on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
|
27
|
+
|
28
|
+
7. Should You wish to submit work that is not Your original creation, You may submit it to Doximity separately from any Contribution, identifying the complete details of its source and of any license or other restriction (including, but not limited to, related patents, trademarks, and license agreements) of which you are personally aware, and conspicuously marking the work as "Submitted on behalf of a third-party: [named here]".
|
29
|
+
|
30
|
+
8. You agree to notify Doximity of any facts or circumstances of which you become aware that would make these representations inaccurate in any respect.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
track_ballast (0.1.0.beta4)
|
5
|
+
activerecord (>= 6.1, < 8.0)
|
6
|
+
activesupport (>= 6.1, < 8.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (7.1.1)
|
12
|
+
activesupport (= 7.1.1)
|
13
|
+
activerecord (7.1.1)
|
14
|
+
activemodel (= 7.1.1)
|
15
|
+
activesupport (= 7.1.1)
|
16
|
+
timeout (>= 0.4.0)
|
17
|
+
activesupport (7.1.1)
|
18
|
+
base64
|
19
|
+
bigdecimal
|
20
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
21
|
+
connection_pool (>= 2.2.5)
|
22
|
+
drb
|
23
|
+
i18n (>= 1.6, < 2)
|
24
|
+
minitest (>= 5.1)
|
25
|
+
mutex_m
|
26
|
+
tzinfo (~> 2.0)
|
27
|
+
ast (2.4.2)
|
28
|
+
base64 (0.2.0)
|
29
|
+
bigdecimal (3.1.4)
|
30
|
+
coderay (1.1.3)
|
31
|
+
concurrent-ruby (1.2.2)
|
32
|
+
connection_pool (2.4.1)
|
33
|
+
diff-lcs (1.5.0)
|
34
|
+
drb (2.2.0)
|
35
|
+
ruby2_keywords
|
36
|
+
ffi (1.16.3)
|
37
|
+
formatador (1.1.0)
|
38
|
+
guard (2.18.1)
|
39
|
+
formatador (>= 0.2.4)
|
40
|
+
listen (>= 2.7, < 4.0)
|
41
|
+
lumberjack (>= 1.0.12, < 2.0)
|
42
|
+
nenv (~> 0.1)
|
43
|
+
notiffany (~> 0.0)
|
44
|
+
pry (>= 0.13.0)
|
45
|
+
shellany (~> 0.0)
|
46
|
+
thor (>= 0.18.1)
|
47
|
+
guard-compat (1.2.1)
|
48
|
+
guard-rspec (4.7.3)
|
49
|
+
guard (~> 2.1)
|
50
|
+
guard-compat (~> 1.1)
|
51
|
+
rspec (>= 2.99.0, < 4.0)
|
52
|
+
i18n (1.14.1)
|
53
|
+
concurrent-ruby (~> 1.0)
|
54
|
+
json (2.7.1)
|
55
|
+
language_server-protocol (3.17.0.3)
|
56
|
+
lint_roller (1.1.0)
|
57
|
+
listen (3.8.0)
|
58
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
59
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
60
|
+
lumberjack (1.2.9)
|
61
|
+
method_source (1.0.0)
|
62
|
+
minitest (5.20.0)
|
63
|
+
mutex_m (0.2.0)
|
64
|
+
nenv (0.3.0)
|
65
|
+
notiffany (0.1.3)
|
66
|
+
nenv (~> 0.1)
|
67
|
+
shellany (~> 0.0)
|
68
|
+
parallel (1.24.0)
|
69
|
+
parser (3.3.0.5)
|
70
|
+
ast (~> 2.4.1)
|
71
|
+
racc
|
72
|
+
pry (0.14.2)
|
73
|
+
coderay (~> 1.1)
|
74
|
+
method_source (~> 1.0)
|
75
|
+
racc (1.7.3)
|
76
|
+
rainbow (3.1.1)
|
77
|
+
rake (13.1.0)
|
78
|
+
rb-fsevent (0.11.2)
|
79
|
+
rb-inotify (0.10.1)
|
80
|
+
ffi (~> 1.0)
|
81
|
+
regexp_parser (2.9.0)
|
82
|
+
rexml (3.2.6)
|
83
|
+
rspec (3.12.0)
|
84
|
+
rspec-core (~> 3.12.0)
|
85
|
+
rspec-expectations (~> 3.12.0)
|
86
|
+
rspec-mocks (~> 3.12.0)
|
87
|
+
rspec-core (3.12.2)
|
88
|
+
rspec-support (~> 3.12.0)
|
89
|
+
rspec-expectations (3.12.3)
|
90
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
91
|
+
rspec-support (~> 3.12.0)
|
92
|
+
rspec-mocks (3.12.6)
|
93
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
94
|
+
rspec-support (~> 3.12.0)
|
95
|
+
rspec-support (3.12.1)
|
96
|
+
rspec_junit_formatter (0.6.0)
|
97
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
98
|
+
rubocop (1.59.0)
|
99
|
+
json (~> 2.3)
|
100
|
+
language_server-protocol (>= 3.17.0)
|
101
|
+
parallel (~> 1.10)
|
102
|
+
parser (>= 3.2.2.4)
|
103
|
+
rainbow (>= 2.2.2, < 4.0)
|
104
|
+
regexp_parser (>= 1.8, < 3.0)
|
105
|
+
rexml (>= 3.2.5, < 4.0)
|
106
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
107
|
+
ruby-progressbar (~> 1.7)
|
108
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
109
|
+
rubocop-ast (1.30.0)
|
110
|
+
parser (>= 3.2.1.0)
|
111
|
+
rubocop-performance (1.20.2)
|
112
|
+
rubocop (>= 1.48.1, < 2.0)
|
113
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
114
|
+
ruby-progressbar (1.13.0)
|
115
|
+
ruby2_keywords (0.0.5)
|
116
|
+
shellany (0.0.1)
|
117
|
+
sqlite3 (1.6.8-arm64-darwin)
|
118
|
+
standard (1.33.0)
|
119
|
+
language_server-protocol (~> 3.17.0.2)
|
120
|
+
lint_roller (~> 1.0)
|
121
|
+
rubocop (~> 1.59.0)
|
122
|
+
standard-custom (~> 1.0.0)
|
123
|
+
standard-performance (~> 1.3)
|
124
|
+
standard-custom (1.0.2)
|
125
|
+
lint_roller (~> 1.0)
|
126
|
+
rubocop (~> 1.50)
|
127
|
+
standard-performance (1.3.1)
|
128
|
+
lint_roller (~> 1.1)
|
129
|
+
rubocop-performance (~> 1.20.2)
|
130
|
+
thor (1.3.0)
|
131
|
+
timeout (0.4.1)
|
132
|
+
tzinfo (2.0.6)
|
133
|
+
concurrent-ruby (~> 1.0)
|
134
|
+
unicode-display_width (2.5.0)
|
135
|
+
yard (0.9.34)
|
136
|
+
|
137
|
+
PLATFORMS
|
138
|
+
arm64-darwin-22
|
139
|
+
|
140
|
+
DEPENDENCIES
|
141
|
+
bundler
|
142
|
+
guard
|
143
|
+
guard-rspec
|
144
|
+
pry
|
145
|
+
rake
|
146
|
+
rspec
|
147
|
+
rspec_junit_formatter
|
148
|
+
sqlite3
|
149
|
+
standard
|
150
|
+
track_ballast!
|
151
|
+
yard
|
152
|
+
|
153
|
+
BUNDLED WITH
|
154
|
+
2.4.10
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2023 Doximity, Inc.
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# TrackBallast
|
2
|
+
|
3
|
+
TrackBallast contains small supporting units of Ruby to use with Rails. It is named after [the small supporting stones that you see alongside railway tracks](https://www.scienceabc.com/pure-sciences/why-are-there-stones-train-ballast-alongside-railway-tracks.html).
|
4
|
+
|
5
|
+
None of these units are quite large enough to be a full Ruby gem on their own, but are yet highly reusable and useful in many Rails applications.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem "track_ballast"
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install track_ballast
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Please see [the code](https://github.com/doximity/track_ballast/tree/master/lib/track_ballast) and [documentation](https://www.rubydoc.info/gems/track_ballast) for individual units.
|
26
|
+
|
27
|
+
You may `require` the entirety of `track_ballast`:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require "track_ballast/all"
|
31
|
+
```
|
32
|
+
|
33
|
+
...or, in your `Gemfile`:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
gem "track_ballast", require: "track_ballast/all"
|
37
|
+
```
|
38
|
+
|
39
|
+
Alternatively, only require each desired unit:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require "track_ballast/callable"
|
43
|
+
|
44
|
+
class MyService
|
45
|
+
extend TrackBallast::Callable
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
require "track_ballast/uuid_management"
|
51
|
+
|
52
|
+
class MyModel < ApplicationRecord
|
53
|
+
include TrackBallast::UuidManagement
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
## Roadmap
|
58
|
+
|
59
|
+
Please see [the Milestones on GitHub](https://github.com/doximity/track_ballast/milestones?direction=asc&sort=title&state=open).
|
60
|
+
|
61
|
+
## Development
|
62
|
+
|
63
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
64
|
+
|
65
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
66
|
+
|
67
|
+
To allow for easy use of individual features of this library, please ensure specs run independently. For example:
|
68
|
+
|
69
|
+
```shell
|
70
|
+
find spec -name '*_spec.rb' -exec bundle exec rspec {} \;
|
71
|
+
```
|
72
|
+
|
73
|
+
## Contributing
|
74
|
+
|
75
|
+
1. See [CONTRIBUTING.md](./CONTRIBUTING.md)
|
76
|
+
2. Fork it ( https://github.com/doximity/track_ballast/fork )
|
77
|
+
3. Create your feature branch (`git checkout -b my-new-feature`)
|
78
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
79
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
80
|
+
6. Create a new Pull Request
|
81
|
+
|
82
|
+
## License
|
83
|
+
|
84
|
+
`track_ballast` is licensed under an Apache 2 license. Contributors are required to sign a contributor license agreement. See LICENSE.txt and CONTRIBUTING.md for more information.
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support"
|
4
|
+
require "active_support/core_ext"
|
5
|
+
|
6
|
+
module TrackBallast
|
7
|
+
# A module for building callable service classes where exactly one method
|
8
|
+
# will ever be called and only the return value of that method matters, not
|
9
|
+
# the class instance itself.
|
10
|
+
#
|
11
|
+
# == Usage
|
12
|
+
#
|
13
|
+
# - Define +initialize+ with the desired arguments
|
14
|
+
# - Define +call+ with the desired logic
|
15
|
+
# - Extend the class with this module
|
16
|
+
#
|
17
|
+
# == Example
|
18
|
+
#
|
19
|
+
# class DivideByTwo
|
20
|
+
# extend TrackBallast::Callable
|
21
|
+
#
|
22
|
+
# def initialize(int)
|
23
|
+
# @int = int
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# def call
|
27
|
+
# int / 2
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# private
|
31
|
+
#
|
32
|
+
# attr_reader :int
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# DivideByTwo.call(10) # => 5
|
36
|
+
module Callable
|
37
|
+
def call(...)
|
38
|
+
new(...).call { yield }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "track_ballast/error"
|
4
|
+
|
5
|
+
module TrackBallast
|
6
|
+
# Raised when logging is attempted without a configured logger
|
7
|
+
class NoLoggerError < Error; end
|
8
|
+
|
9
|
+
class << self
|
10
|
+
# @!visibility private
|
11
|
+
attr_writer :logger
|
12
|
+
|
13
|
+
# Internal logger for +TrackBallast+.
|
14
|
+
#
|
15
|
+
# This defaults to +Rails.logger+. This +logger+ method may be removed in
|
16
|
+
# the future if we determine that +Rails.logger+ is more sensible given the
|
17
|
+
# focus of the library. Please do not use +TrackBallast.logger+ outside of
|
18
|
+
# this gem.
|
19
|
+
#
|
20
|
+
# @!visibility private
|
21
|
+
# @return [ActiveSupport::TaggedLogging] a tagged logger
|
22
|
+
def logger
|
23
|
+
if @logger
|
24
|
+
@logger
|
25
|
+
elsif defined?(Rails)
|
26
|
+
# This will short-circuit to be `@logger` on future runs
|
27
|
+
@logger = Rails.logger
|
28
|
+
else
|
29
|
+
raise NoLoggerError, "TrackBallast.logger is not configured"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "securerandom"
|
4
|
+
|
5
|
+
require "active_record"
|
6
|
+
require "active_support"
|
7
|
+
require "active_support/core_ext"
|
8
|
+
require "track_ballast/logger"
|
9
|
+
|
10
|
+
module TrackBallast
|
11
|
+
# Manage a +uuid+ column alongside an autoincrementing +id+ column for an
|
12
|
+
# +ActiveRecord+ model.
|
13
|
+
#
|
14
|
+
# == Additional Features
|
15
|
+
#
|
16
|
+
# - Adds presence validation if the +uuid+ column is non-nullable
|
17
|
+
# - Validates v4 UUIDs at creation time using the +not_v4_uuid+ error on
|
18
|
+
# +uuid+ and logs violations with a +invalid-uuid+ tag
|
19
|
+
#
|
20
|
+
# == Usage
|
21
|
+
#
|
22
|
+
# === Adding a Column
|
23
|
+
#
|
24
|
+
# Add a +uuid+ column to your model such that it can be written as a string.
|
25
|
+
#
|
26
|
+
# Suggested:
|
27
|
+
#
|
28
|
+
# t.string "uuid", limit: 36, null: false, unique: true
|
29
|
+
#
|
30
|
+
# Alternatively, for MySQL, consider using a binary column:
|
31
|
+
#
|
32
|
+
# t.binary "uuid", limit: 16, null: false, unique: true
|
33
|
+
#
|
34
|
+
# ...and define the +uuid+ attribute using the +mysql-binuuid-rails+ gem:
|
35
|
+
#
|
36
|
+
# attribute :uuid, MySQLBinUUID::Type.new
|
37
|
+
#
|
38
|
+
# This has performance and storage space benefits, but please note that this
|
39
|
+
# may increase the difficulty of working with this column outside of Rails.
|
40
|
+
#
|
41
|
+
# Both forms of UUID column are acceptable and left as a decision for the
|
42
|
+
# implementor.
|
43
|
+
#
|
44
|
+
# === Include the module
|
45
|
+
#
|
46
|
+
# After adding the column, simply +include+ the module:
|
47
|
+
#
|
48
|
+
# class MyModel < ApplicationRecord
|
49
|
+
# include TrackBallast::UuidManagement
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
module UuidManagement
|
53
|
+
extend ActiveSupport::Concern
|
54
|
+
|
55
|
+
included do
|
56
|
+
with_options if: :uuid_exists? do
|
57
|
+
after_initialize :uuid_generate, if: :new_record?
|
58
|
+
before_validation :uuid_generate, on: :create
|
59
|
+
|
60
|
+
validate :v4_uuid, on: :create
|
61
|
+
with_options unless: :uuid_nullable? do
|
62
|
+
validates :uuid, presence: true, length: {is: 36}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
REGEXP_UUID_V4 = /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i
|
70
|
+
|
71
|
+
def v4_uuid
|
72
|
+
return if uuid.match(REGEXP_UUID_V4)
|
73
|
+
|
74
|
+
TrackBallast.logger.tagged("invalid-uuid") do |logger|
|
75
|
+
logger.error(class: self.class.name, uuid: uuid, caller: caller.join("\n"))
|
76
|
+
end
|
77
|
+
|
78
|
+
errors.add :uuid, :not_v4_uuid, message: "is not a v4 UUID"
|
79
|
+
end
|
80
|
+
|
81
|
+
def uuid_exists?
|
82
|
+
!uuid_column.nil?
|
83
|
+
end
|
84
|
+
|
85
|
+
def uuid_nullable?
|
86
|
+
uuid_column.null
|
87
|
+
end
|
88
|
+
|
89
|
+
def uuid_column
|
90
|
+
self.class.columns.find { |column| column.name == "uuid" }
|
91
|
+
end
|
92
|
+
|
93
|
+
def uuid_generate
|
94
|
+
return unless try(:uuid).blank?
|
95
|
+
|
96
|
+
self.uuid = SecureRandom.uuid
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require "track_ballast/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "track_ballast"
|
9
|
+
spec.version = TrackBallast::VERSION
|
10
|
+
spec.authors = ["Benjamin Oakes"]
|
11
|
+
spec.email = ["boakes@doximity.com"]
|
12
|
+
|
13
|
+
spec.summary = "Small supporting units of Ruby to use with Rails"
|
14
|
+
spec.homepage = "https://github.com/doximity/track_ballast"
|
15
|
+
spec.license = "APACHE-2.0"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/doximity/track_ballast/blob/main/CHANGELOG.md"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.executables = []
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_dependency "activerecord", ">= 6.1", "< 8.0"
|
30
|
+
spec.add_dependency "activesupport", ">= 6.1", "< 8.0"
|
31
|
+
spec.add_development_dependency "bundler"
|
32
|
+
spec.add_development_dependency "guard"
|
33
|
+
spec.add_development_dependency "guard-rspec"
|
34
|
+
spec.add_development_dependency "pry"
|
35
|
+
spec.add_development_dependency "rake"
|
36
|
+
spec.add_development_dependency "rspec"
|
37
|
+
spec.add_development_dependency "rspec_junit_formatter"
|
38
|
+
spec.add_development_dependency "sqlite3"
|
39
|
+
spec.add_development_dependency "standard"
|
40
|
+
spec.add_development_dependency "yard"
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,246 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: track_ballast
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.beta4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Benjamin Oakes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-01-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6.1'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '8.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '6.1'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '8.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: activesupport
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '6.1'
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '8.0'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '6.1'
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '8.0'
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: bundler
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: guard
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: guard-rspec
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: pry
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: rake
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
type: :development
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: rspec
|
125
|
+
requirement: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
type: :development
|
131
|
+
prerelease: false
|
132
|
+
version_requirements: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: rspec_junit_formatter
|
139
|
+
requirement: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
type: :development
|
145
|
+
prerelease: false
|
146
|
+
version_requirements: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
- !ruby/object:Gem::Dependency
|
152
|
+
name: sqlite3
|
153
|
+
requirement: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
type: :development
|
159
|
+
prerelease: false
|
160
|
+
version_requirements: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
- !ruby/object:Gem::Dependency
|
166
|
+
name: standard
|
167
|
+
requirement: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - ">="
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
type: :development
|
173
|
+
prerelease: false
|
174
|
+
version_requirements: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
179
|
+
- !ruby/object:Gem::Dependency
|
180
|
+
name: yard
|
181
|
+
requirement: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - ">="
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '0'
|
186
|
+
type: :development
|
187
|
+
prerelease: false
|
188
|
+
version_requirements: !ruby/object:Gem::Requirement
|
189
|
+
requirements:
|
190
|
+
- - ">="
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: '0'
|
193
|
+
description:
|
194
|
+
email:
|
195
|
+
- boakes@doximity.com
|
196
|
+
executables: []
|
197
|
+
extensions: []
|
198
|
+
extra_rdoc_files: []
|
199
|
+
files:
|
200
|
+
- ".gitignore"
|
201
|
+
- ".rspec"
|
202
|
+
- ".ruby-version"
|
203
|
+
- CHANGELOG.md
|
204
|
+
- CONTRIBUTING.md
|
205
|
+
- Gemfile
|
206
|
+
- Gemfile.lock
|
207
|
+
- LICENSE.txt
|
208
|
+
- README.md
|
209
|
+
- Rakefile
|
210
|
+
- bin/console
|
211
|
+
- bin/setup
|
212
|
+
- lib/track_ballast.rb
|
213
|
+
- lib/track_ballast/all.rb
|
214
|
+
- lib/track_ballast/callable.rb
|
215
|
+
- lib/track_ballast/error.rb
|
216
|
+
- lib/track_ballast/logger.rb
|
217
|
+
- lib/track_ballast/uuid_management.rb
|
218
|
+
- lib/track_ballast/version.rb
|
219
|
+
- track_ballast.gemspec
|
220
|
+
homepage: https://github.com/doximity/track_ballast
|
221
|
+
licenses:
|
222
|
+
- APACHE-2.0
|
223
|
+
metadata:
|
224
|
+
homepage_uri: https://github.com/doximity/track_ballast
|
225
|
+
source_code_uri: https://github.com/doximity/track_ballast
|
226
|
+
changelog_uri: https://github.com/doximity/track_ballast/blob/main/CHANGELOG.md
|
227
|
+
post_install_message:
|
228
|
+
rdoc_options: []
|
229
|
+
require_paths:
|
230
|
+
- lib
|
231
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
232
|
+
requirements:
|
233
|
+
- - ">="
|
234
|
+
- !ruby/object:Gem::Version
|
235
|
+
version: '0'
|
236
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
237
|
+
requirements:
|
238
|
+
- - ">"
|
239
|
+
- !ruby/object:Gem::Version
|
240
|
+
version: 1.3.1
|
241
|
+
requirements: []
|
242
|
+
rubygems_version: 3.4.10
|
243
|
+
signing_key:
|
244
|
+
specification_version: 4
|
245
|
+
summary: Small supporting units of Ruby to use with Rails
|
246
|
+
test_files: []
|