uuid_attribute 0.9.0 → 0.9.2
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 +7 -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: '044226208a5f82b69965d3614d69e8498d275ba54a8f74a2df5710bdaee8ed81'
|
4
|
+
data.tar.gz: b52bbb3dc7f2ba502e6ea59e9524903e0ffde4bddb57aec9f9fa2f1615ddd1bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ef05bd5a47da6b30efc5257914b18f7b48796f2f054635f522e83e269f7c3479bc38ebcaed0f929f47d87c489078be3a13a94fd52f14122a652c5cb86e74067
|
7
|
+
data.tar.gz: 839cfd50e258caf09be260ef060efafd57d27cdcf5a461f044173ddc0f1ced698d34cba136d3b2ec32c1ac6beddadd57f3a006db5f7fe0ab09a0025e0fcd7046
|
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,19 @@ 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
|
+
false
|
55
|
+
else
|
56
|
+
true
|
53
57
|
end
|
54
58
|
end
|
55
59
|
|
56
60
|
config.after_initialize do
|
61
|
+
return if ARGV.include? "assets:precompile"
|
62
|
+
|
57
63
|
ActiveRecord::Type.register(:uuid, ::UuidAttribute::UUID)
|
58
64
|
|
59
65
|
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.2
|
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
|