ulid-rails 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/bin/run_tests +3 -1
- data/docker-compose.yml +3 -3
- data/lib/ulid/rails.rb +13 -13
- data/lib/ulid/rails/type.rb +1 -1
- data/lib/ulid/rails/version.rb +1 -1
- data/ulid-rails.gemspec +2 -2
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 344d5b35daef598e2fe1116ad9bebea5d24cf9b6c1c2150344f2f1e5b25f0989
|
4
|
+
data.tar.gz: ecf448dea0921bf022a7888d0f2b90f23e27f08b5e103f6aa3669e0f71b0913a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 573a3e355e9487ccea553ce0041b831ba10d45d578906022ccbd99a9b672d9859d9cc9f1ae324bab61d68f9c0669609d1bfdfffe870d0a498309be876d6f68c8
|
7
|
+
data.tar.gz: d59ccebd6290359ca5b1e1508275aa16eee8e061455a35cd29ee2439acf07cb777d9ca013b855abaaec0a08087aa2a23d05f43e710b2c313c782ca74e4a0fc82
|
data/README.md
CHANGED
@@ -27,7 +27,7 @@ Specify `id: false` to `create_table` and add `id` column as 16-byte binary type
|
|
27
27
|
```ruby
|
28
28
|
def change
|
29
29
|
create_table :users, id: false do |t|
|
30
|
-
t.binary :id, limit: 16, primary_key: true
|
30
|
+
t.binary :id, limit: 16, primary_key: true
|
31
31
|
# ...
|
32
32
|
end
|
33
33
|
end
|
@@ -63,7 +63,7 @@ end
|
|
63
63
|
|
64
64
|
### `created_at` virtual column
|
65
65
|
|
66
|
-
**MySQL Only (for now)**
|
66
|
+
**MySQL 5.7 and higher Only (for now)**
|
67
67
|
|
68
68
|
You can define a "virtual column" in MySQL DB that acts same as a physical column.
|
69
69
|
Defining the virtual `created_at` is kind of comlicated so this gem provides a helper method for it.
|
data/bin/run_tests
CHANGED
data/docker-compose.yml
CHANGED
@@ -2,7 +2,7 @@ version: '3.6'
|
|
2
2
|
services:
|
3
3
|
test:
|
4
4
|
image: ruby:2.6
|
5
|
-
command: sh -c "rm Gemfile.lock && bundle install && bin/run_tests"
|
5
|
+
command: sh -c "rm -f Gemfile.lock && bundle install && bin/run_tests"
|
6
6
|
depends_on:
|
7
7
|
- mysql56
|
8
8
|
- mysql57
|
@@ -12,7 +12,7 @@ services:
|
|
12
12
|
volumes:
|
13
13
|
- bundle:/usr/local/bundle
|
14
14
|
- .:/app
|
15
|
-
|
15
|
+
|
16
16
|
mysql56:
|
17
17
|
image: mysql:5.6
|
18
18
|
environment:
|
@@ -41,4 +41,4 @@ services:
|
|
41
41
|
healthcheck:
|
42
42
|
test: echo "\\l" | psql -U postgre
|
43
43
|
volumes:
|
44
|
-
bundle:
|
44
|
+
bundle:
|
data/lib/ulid/rails.rb
CHANGED
@@ -15,27 +15,27 @@ module ULID
|
|
15
15
|
def ulid(column_name, primary_key: false, auto_generate: nil)
|
16
16
|
attribute column_name, ULID::Rails::Type.new
|
17
17
|
|
18
|
-
auto_generate =
|
18
|
+
auto_generate = primary_key ? primary_key : auto_generate
|
19
19
|
if auto_generate
|
20
20
|
before_create do
|
21
21
|
send("#{column_name}=", ULID.generate) if send(column_name).nil?
|
22
22
|
end
|
23
23
|
end
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
26
|
+
def ulid_extract_timestamp(ulid_column, timestamp_column = :created_at)
|
27
|
+
define_method timestamp_column do
|
28
|
+
at = super() rescue nil
|
29
|
+
if !at && (id_val = send(ulid_column))
|
30
|
+
Time.zone.at((Base32::Crockford.decode(id_val) >> 80) / 1000.0)
|
31
|
+
else
|
32
|
+
at
|
33
33
|
end
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
36
|
+
if timestamp_column.to_s == "created_at"
|
37
|
+
define_singleton_method(:timestamp_attributes_for_create) do
|
38
|
+
[]
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
data/lib/ulid/rails/type.rb
CHANGED
@@ -18,7 +18,7 @@ module ULID
|
|
18
18
|
|
19
19
|
value = value.to_s if value.is_a?(Data)
|
20
20
|
value = value.unpack("H*")[0] if value.encoding == Encoding::ASCII_8BIT
|
21
|
-
value = value[2
|
21
|
+
value = value[2..-1] if value.start_with?("\\x")
|
22
22
|
|
23
23
|
value.length == 32 ? @formatter.format(value) : super
|
24
24
|
end
|
data/lib/ulid/rails/version.rb
CHANGED
data/ulid-rails.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_dependency "activesupport", ">= 5.0"
|
27
27
|
spec.add_dependency "activemodel", ">= 5.0"
|
28
28
|
spec.add_dependency "activerecord", ">= 5.0"
|
29
|
-
spec.add_development_dependency "bundler"
|
30
|
-
spec.add_development_dependency "rake"
|
29
|
+
spec.add_development_dependency "bundler"
|
30
|
+
spec.add_development_dependency "rake"
|
31
31
|
spec.add_development_dependency "minitest", "~> 5.0"
|
32
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ulid-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kazunori Kajihiro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ulid
|
@@ -84,30 +84,30 @@ dependencies:
|
|
84
84
|
name: bundler
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rake
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: minitest
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|