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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c37eb5b4b0722d0858a1c08682e89a8285350ab1d151bc90bbb6aaf1c6cff5d
4
- data.tar.gz: 9bd6b0bff5eb157b998f04b26b7eb75e3b53d90c4820e2dcbc9ede7c8a1246b8
3
+ metadata.gz: 344d5b35daef598e2fe1116ad9bebea5d24cf9b6c1c2150344f2f1e5b25f0989
4
+ data.tar.gz: ecf448dea0921bf022a7888d0f2b90f23e27f08b5e103f6aa3669e0f71b0913a
5
5
  SHA512:
6
- metadata.gz: ab1f5cf9796884e8845a67bf13a3e6b69f2e3d48c2b21c23ff5d0f1836fdbd6da1850dcb9292be74cad38476f4df3f4cd46306d66d2bdc203c7da50c24861ce2
7
- data.tar.gz: f8300abe5bd288884ae1d8a24a12f08e3b6c248c144cc68f564fe567ff7c7fa213ce9a3110a1b5125a9ec9a38220afa139938cb12ce0b779532b613c6390e9a4
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 # MySQL
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
@@ -1,5 +1,7 @@
1
1
  #!/bin/bash
2
2
 
3
+ set -e
4
+
3
5
  test_with_db() {
4
6
  echo "Testing with $1"
5
7
  DB=$1 bundle exec rake
@@ -20,4 +22,4 @@ $DIR/wait-for-it.sh mysql80:3306
20
22
  test_with_db "mysql80"
21
23
 
22
24
  $DIR/wait-for-it.sh pg12:5432
23
- test_with_db "pg12"
25
+ test_with_db "pg12"
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 = auto_generate.nil? ? primary_key : false
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
- def ulid_extract_timestamp(ulid_column, timestamp_column = :created_at)
26
- define_method timestamp_column do
27
- at = super() rescue nil
28
- if !at && (id_val = send(ulid_column))
29
- Time.zone.at((Base32::Crockford.decode(id_val) >> 80) / 1000.0)
30
- else
31
- at
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
- if timestamp_column.to_s == "created_at"
36
- define_singleton_method(:timestamp_attributes_for_create) do
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
@@ -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..] if value.start_with?("\\x")
21
+ value = value[2..-1] if value.start_with?("\\x")
22
22
 
23
23
  value.length == 32 ? @formatter.format(value) : super
24
24
  end
@@ -1,5 +1,5 @@
1
1
  module ULID
2
2
  module Rails
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
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", "~> 1.16"
30
- spec.add_development_dependency "rake", "~> 10.0"
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.3.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: 2019-11-24 00:00:00.000000000 Z
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: '1.16'
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: '1.16'
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: '10.0'
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: '10.0'
110
+ version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: minitest
113
113
  requirement: !ruby/object:Gem::Requirement