uuid_attribute 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -9
- data/lib/uuid_attribute/railtie.rb +8 -1
- data/lib/uuid_attribute/utils.rb +3 -1
- data/lib/uuid_attribute/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e716f18577f556aa807d4ad19aa1f6cd62900f7ea5faab4ea3f88fb4cc8e3d5a
|
4
|
+
data.tar.gz: 22161c78f0e24c4117306db0c6d70b27665f911385ade24748d09619acefc657
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90698cabeeb889fc28c07ab0001e53575db198b611707dc0fb640348b32c2d9712f3c861ccfdbcfa3aceb56d8f85cb6255c3cae6a591697792b135140824ee7c
|
7
|
+
data.tar.gz: ef6d0daa754d19d805367b00646789b1813ea9db391bad35129ca9e06d67a165c3779047d1e227110b857a808b8a2499e767081316c381e92ff7e6e6befc5ce0
|
data/README.md
CHANGED
@@ -12,13 +12,15 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
12
12
|
|
13
13
|
## Usage
|
14
14
|
|
15
|
-
TODO: Write usage instructions here
|
16
|
-
|
17
15
|
```
|
18
16
|
class YourModel < ApplicationRecord
|
19
|
-
attribute :id, :uuid, default: -> { SecureRandom.uuid }
|
20
17
|
end
|
21
18
|
|
19
|
+
model = YourModel.create( ... )
|
20
|
+
YourModel:0x00007f85774135a8
|
21
|
+
id: "5iLEaLFZUeD6Dg8nnfSiCZ",
|
22
|
+
... >
|
23
|
+
|
22
24
|
Or if you want to disable auto detect of UUIDs
|
23
25
|
|
24
26
|
UuidAttribute.setup do |config|
|
@@ -41,12 +43,6 @@ release a new version, update the version number in `version.rb`, and then run
|
|
41
43
|
git commits and the created tag, and push the `.gem` file to
|
42
44
|
[rubygems.org](https://rubygems.org).
|
43
45
|
|
44
|
-
## TODO
|
45
|
-
|
46
|
-
Write tests for each supported rails versions. See examples at:
|
47
|
-
https://github.com/rails/rails/tree/main/activerecord
|
48
|
-
https://github.com/heartcombo/simple_form/tree/main/gemfiles
|
49
|
-
|
50
46
|
## Contributing
|
51
47
|
|
52
48
|
Bug reports and pull requests are welcome on GitHub at
|
@@ -47,13 +47,20 @@ module UuidAttribute
|
|
47
47
|
|
48
48
|
default = nil
|
49
49
|
default = -> { SecureRandom.uuid } if att.eql? "id"
|
50
|
-
model.
|
50
|
+
model.attribute att, ::UuidAttribute::UUID.new, default: default
|
51
51
|
end
|
52
52
|
end
|
53
|
+
rescue ActiveRecord::NoDatabaseError
|
54
|
+
puts "NO DATABASE"
|
55
|
+
false
|
56
|
+
else
|
57
|
+
puts "CONFIGURE BINARY"
|
58
|
+
true
|
53
59
|
end
|
54
60
|
end
|
55
61
|
|
56
62
|
config.after_initialize do
|
63
|
+
puts "REGISTERING UUID"
|
57
64
|
ActiveRecord::Type.register(:uuid, ::UuidAttribute::UUID)
|
58
65
|
|
59
66
|
configure_binary_ids if UuidAttribute.auto_detect_binary_ids
|
data/lib/uuid_attribute/utils.rb
CHANGED
@@ -5,7 +5,7 @@ module UuidAttribute
|
|
5
5
|
class Utils
|
6
6
|
class << self
|
7
7
|
def normalize(uuid_string)
|
8
|
-
uuid_string
|
8
|
+
uuid_string&.gsub("-", "")&.upcase
|
9
9
|
end
|
10
10
|
|
11
11
|
def hex_from_binary(bytes)
|
@@ -23,6 +23,8 @@ module UuidAttribute
|
|
23
23
|
case str.length
|
24
24
|
when 32
|
25
25
|
format_uuid(str)
|
26
|
+
when 34
|
27
|
+
format_uuid(str)
|
26
28
|
when 16
|
27
29
|
format_uuid(hex_from_binary(str))
|
28
30
|
when 22
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uuid_attribute
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Negri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|