sql_enum 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/.github/workflows/tests.yml +19 -3
- data/.gitignore +2 -0
- data/Appraisals +12 -0
- data/Dockerfile +4 -7
- data/Gemfile.lock +44 -28
- data/README.md +1 -1
- data/docker-compose.yml +1 -1
- data/gemfiles/rails_5.1.gemfile +7 -0
- data/gemfiles/rails_5.2.gemfile +7 -0
- data/gemfiles/rails_6.0.gemfile +7 -0
- data/gemfiles/rails_6.1.gemfile +7 -0
- data/gemfiles/rails_7.0.gemfile +7 -0
- data/lib/active_record/connection_adapters/abstract_mysql.rb +3 -0
- data/lib/active_record/connection_adapters/mysql/column_methods.rb +1 -1
- data/lib/sql_enum/class_methods.rb +27 -4
- data/lib/sql_enum/enum_column.rb +7 -7
- data/lib/sql_enum/enum_type.rb +12 -0
- data/lib/sql_enum/version.rb +1 -1
- data/lib/sql_enum.rb +1 -0
- data/sql_enum.gemspec +9 -2
- metadata +57 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4f885963c1a9b5c4d6612807ea7627f34fc455a730a45ed93fe380bc2a4d0ff
|
4
|
+
data.tar.gz: 8489d2a5a017117bb1d5a0d5bb88ccab8f11e4be19a915374ee3d12222d45f76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f4ed451ed9dd0d9f6b0e0d5475efadea5bc1de0d3f19e54bfd2066dfb2685cdb7e9f601bd1ca5b977af17b0df19c89860b5ee2bc5791fbdaf19f2644bbd32de
|
7
|
+
data.tar.gz: c27592b8fc57952f8237d8dd19c21e50335b7f9a5de2081074a331b5972f7fa4eacbd61745e3da3424086f5f35e64a2df909d866973d96c3268fa758bdd2f36c
|
data/.github/workflows/tests.yml
CHANGED
@@ -2,15 +2,31 @@ name: Tests
|
|
2
2
|
|
3
3
|
on:
|
4
4
|
push:
|
5
|
-
branches: [
|
5
|
+
branches: [ main ]
|
6
6
|
pull_request:
|
7
7
|
|
8
8
|
jobs:
|
9
9
|
rspec:
|
10
|
+
strategy:
|
11
|
+
matrix:
|
12
|
+
ruby:
|
13
|
+
- '2.7'
|
14
|
+
- '3.0'
|
15
|
+
- '3.1'
|
16
|
+
- '3.2'
|
17
|
+
rails:
|
18
|
+
- '6.0'
|
19
|
+
- '6.1'
|
20
|
+
|
10
21
|
runs-on: ubuntu-latest
|
11
22
|
|
23
|
+
name: RSpec (Rails ${{ matrix.rails }}) (Ruby ${{ matrix.ruby }})
|
24
|
+
|
12
25
|
steps:
|
13
26
|
- uses: actions/checkout@v2
|
14
|
-
|
27
|
+
- uses: ruby/setup-ruby@v1
|
28
|
+
with:
|
29
|
+
ruby-version: ${{ matrix.ruby }}
|
30
|
+
bundler-cache: true
|
15
31
|
- name: Test
|
16
|
-
run: docker-compose run --rm rspec
|
32
|
+
run: docker-compose run --rm rspec bundle exec appraisal rails-${{ matrix.rails }} rspec
|
data/.gitignore
CHANGED
data/Appraisals
ADDED
data/Dockerfile
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
FROM ruby:3.0
|
2
2
|
|
3
|
-
# throw errors if Gemfile has been modified since Gemfile.lock
|
4
|
-
RUN bundle config --global frozen 1
|
5
|
-
|
6
3
|
WORKDIR /usr/src/app
|
7
4
|
|
8
|
-
|
9
|
-
RUN mkdir -p lib/sql_enum
|
5
|
+
RUN mkdir -p lib/sql_enum gemfiles
|
10
6
|
COPY lib/sql_enum/version.rb ./lib/sql_enum/
|
11
|
-
COPY
|
12
|
-
|
7
|
+
COPY gemfiles/*.gemfile gemfiles/
|
8
|
+
COPY sql_enum.gemspec Gemfile Gemfile.lock Appraisals ./
|
9
|
+
RUN bundle install && exec appraisal install
|
data/Gemfile.lock
CHANGED
@@ -1,54 +1,70 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sql_enum (0.
|
5
|
-
activerecord (>=
|
6
|
-
activesupport (>=
|
4
|
+
sql_enum (0.4.0)
|
5
|
+
activerecord (>= 6.0, < 7.0)
|
6
|
+
activesupport (>= 6.0, < 7.0)
|
7
7
|
mysql2
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: https://gem-proxy.chime.com/
|
11
11
|
specs:
|
12
|
-
activemodel (6.1.
|
13
|
-
activesupport (= 6.1.
|
14
|
-
activerecord (6.1.
|
15
|
-
activemodel (= 6.1.
|
16
|
-
activesupport (= 6.1.
|
17
|
-
activesupport (6.1.
|
12
|
+
activemodel (6.1.7.6)
|
13
|
+
activesupport (= 6.1.7.6)
|
14
|
+
activerecord (6.1.7.6)
|
15
|
+
activemodel (= 6.1.7.6)
|
16
|
+
activesupport (= 6.1.7.6)
|
17
|
+
activesupport (6.1.7.6)
|
18
18
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
19
|
i18n (>= 1.6, < 2)
|
20
20
|
minitest (>= 5.1)
|
21
21
|
tzinfo (~> 2.0)
|
22
22
|
zeitwerk (~> 2.3)
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
appraisal (2.5.0)
|
24
|
+
bundler
|
25
|
+
rake
|
26
|
+
thor (>= 0.14.0)
|
27
|
+
concurrent-ruby (1.2.2)
|
28
|
+
debug (1.8.0)
|
29
|
+
irb (>= 1.5.0)
|
30
|
+
reline (>= 0.3.1)
|
31
|
+
diff-lcs (1.5.0)
|
32
|
+
i18n (1.14.1)
|
26
33
|
concurrent-ruby (~> 1.0)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
io-console (0.6.0)
|
35
|
+
irb (1.7.4)
|
36
|
+
reline (>= 0.3.6)
|
37
|
+
minitest (5.19.0)
|
38
|
+
mysql2 (0.5.5)
|
39
|
+
rake (13.0.6)
|
40
|
+
reline (0.3.8)
|
41
|
+
io-console (~> 0.5)
|
42
|
+
rspec (3.12.0)
|
43
|
+
rspec-core (~> 3.12.0)
|
44
|
+
rspec-expectations (~> 3.12.0)
|
45
|
+
rspec-mocks (~> 3.12.0)
|
46
|
+
rspec-core (3.12.2)
|
47
|
+
rspec-support (~> 3.12.0)
|
48
|
+
rspec-expectations (3.12.3)
|
37
49
|
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
-
rspec-support (~> 3.
|
39
|
-
rspec-mocks (3.
|
50
|
+
rspec-support (~> 3.12.0)
|
51
|
+
rspec-mocks (3.12.6)
|
40
52
|
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
-
rspec-support (~> 3.
|
42
|
-
rspec-support (3.
|
43
|
-
|
53
|
+
rspec-support (~> 3.12.0)
|
54
|
+
rspec-support (3.12.1)
|
55
|
+
thor (1.2.2)
|
56
|
+
tzinfo (2.0.6)
|
44
57
|
concurrent-ruby (~> 1.0)
|
45
|
-
zeitwerk (2.
|
58
|
+
zeitwerk (2.6.11)
|
46
59
|
|
47
60
|
PLATFORMS
|
48
61
|
ruby
|
62
|
+
x86_64-linux
|
49
63
|
|
50
64
|
DEPENDENCIES
|
65
|
+
appraisal
|
51
66
|
bundler
|
67
|
+
debug
|
52
68
|
rake (~> 13.0)
|
53
69
|
rspec (~> 3.0)
|
54
70
|
sql_enum!
|
data/README.md
CHANGED
@@ -66,4 +66,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
66
66
|
|
67
67
|
## Code of Conduct
|
68
68
|
|
69
|
-
Everyone interacting in the SqlEnum project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/1debit/sql_enum/blob/
|
69
|
+
Everyone interacting in the SqlEnum project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/1debit/sql_enum/blob/main/CODE_OF_CONDUCT.md).
|
data/docker-compose.yml
CHANGED
@@ -3,18 +3,41 @@ module SqlEnum
|
|
3
3
|
def sql_enum(column_name, options = {})
|
4
4
|
# Query values
|
5
5
|
enum_column = EnumColumn.new(table_name, column_name)
|
6
|
-
|
6
|
+
values_map = enum_column.values.to_h { |value| [value.to_sym, value.to_s] }
|
7
7
|
|
8
8
|
# Check option defaults
|
9
9
|
prefix = options.fetch(:_prefix, !!SqlEnum.configuration&.default_prefix)
|
10
10
|
suffix = options.fetch(:_suffix, !!SqlEnum.configuration&.default_suffix)
|
11
11
|
|
12
12
|
# Define enum using Rails enum
|
13
|
-
enum(column_name =>
|
13
|
+
enum(column_name => values_map, _prefix: prefix, _suffix: suffix)
|
14
14
|
|
15
15
|
# Override reader to return symbols
|
16
|
-
|
17
|
-
|
16
|
+
type_definition = ->(subtype) { EnumType.new(attr, send(column_name.to_s.pluralize), subtype) }
|
17
|
+
case method(:decorate_attribute_type).arity
|
18
|
+
when 2 # Rails 5.1, 5.2, 6.0
|
19
|
+
decorate_attribute_type(column_name, :enum, &type_definition)
|
20
|
+
else
|
21
|
+
decorate_attribute_type(column_name, &type_definition)
|
22
|
+
end
|
23
|
+
|
24
|
+
prefix_str = format_affix(column_name, prefix, suffix: '_')
|
25
|
+
suffix_str = format_affix(column_name, suffix, prefix: '_')
|
26
|
+
|
27
|
+
# Fix query methods to compare symbols to symbols
|
28
|
+
values_map.each_value do |value|
|
29
|
+
method_name = "#{prefix_str}#{value}#{suffix_str}"
|
30
|
+
define_method("#{method_name}?") { self[column_name] == value.to_sym }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def format_affix(column_name, affix, prefix: '', suffix: '')
|
37
|
+
if affix == true
|
38
|
+
"#{prefix}#{column_name}#{suffix}"
|
39
|
+
elsif affix
|
40
|
+
"#{prefix}#{affix}#{suffix}"
|
18
41
|
end
|
19
42
|
end
|
20
43
|
end
|
data/lib/sql_enum/enum_column.rb
CHANGED
@@ -21,13 +21,13 @@ module SqlEnum
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def schema_values_query
|
24
|
-
<<~
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
<<~SQL
|
25
|
+
SELECT column_type
|
26
|
+
FROM information_schema.COLUMNS
|
27
|
+
WHERE TABLE_SCHEMA = '#{database_name}'
|
28
|
+
AND TABLE_NAME = '#{table_name}'
|
29
|
+
AND COLUMN_NAME = '#{column_name}'
|
30
|
+
SQL
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
data/lib/sql_enum/version.rb
CHANGED
data/lib/sql_enum.rb
CHANGED
@@ -20,5 +20,6 @@ require_relative 'active_record/connection_adapters/mysql/column_methods'
|
|
20
20
|
require_relative 'sql_enum/version'
|
21
21
|
require_relative 'sql_enum/configuration'
|
22
22
|
require_relative 'sql_enum/enum_column'
|
23
|
+
require_relative 'sql_enum/enum_type'
|
23
24
|
require_relative 'sql_enum/class_methods'
|
24
25
|
require_relative 'sql_enum/active_record'
|
data/sql_enum.gemspec
CHANGED
@@ -13,6 +13,11 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = "https://github.com/1debit/sql_enum"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
+
spec.metadata = {
|
17
|
+
'homepage_uri' => spec.homepage,
|
18
|
+
'source_code_uri' => spec.homepage,
|
19
|
+
}
|
20
|
+
|
16
21
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
22
|
f.match(%r{^(test|spec|features)/})
|
18
23
|
end
|
@@ -20,11 +25,13 @@ Gem::Specification.new do |spec|
|
|
20
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
26
|
spec.require_paths = ["lib"]
|
22
27
|
|
23
|
-
spec.add_dependency "activesupport", ">=
|
24
|
-
spec.add_dependency "activerecord", ">=
|
28
|
+
spec.add_dependency "activesupport", ">= 6.0", "< 7.0"
|
29
|
+
spec.add_dependency "activerecord", ">= 6.0", "< 7.0"
|
25
30
|
spec.add_dependency "mysql2"
|
26
31
|
|
32
|
+
spec.add_development_dependency "appraisal"
|
27
33
|
spec.add_development_dependency "bundler"
|
34
|
+
spec.add_development_dependency "debug"
|
28
35
|
spec.add_development_dependency "rake", "~> 13.0"
|
29
36
|
spec.add_development_dependency "rspec", "~> 3.0"
|
30
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sql_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fletcher Fowler
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,28 +16,40 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
29
|
+
version: '6.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '7.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: activerecord
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - ">="
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
39
|
+
version: '6.0'
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '7.0'
|
34
43
|
type: :runtime
|
35
44
|
prerelease: false
|
36
45
|
version_requirements: !ruby/object:Gem::Requirement
|
37
46
|
requirements:
|
38
47
|
- - ">="
|
39
48
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
49
|
+
version: '6.0'
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '7.0'
|
41
53
|
- !ruby/object:Gem::Dependency
|
42
54
|
name: mysql2
|
43
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +64,20 @@ dependencies:
|
|
52
64
|
- - ">="
|
53
65
|
- !ruby/object:Gem::Version
|
54
66
|
version: '0'
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: appraisal
|
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'
|
55
81
|
- !ruby/object:Gem::Dependency
|
56
82
|
name: bundler
|
57
83
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +92,20 @@ dependencies:
|
|
66
92
|
- - ">="
|
67
93
|
- !ruby/object:Gem::Version
|
68
94
|
version: '0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: debug
|
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'
|
69
109
|
- !ruby/object:Gem::Dependency
|
70
110
|
name: rake
|
71
111
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,6 +146,7 @@ files:
|
|
106
146
|
- ".gitignore"
|
107
147
|
- ".rspec"
|
108
148
|
- ".travis.yml"
|
149
|
+
- Appraisals
|
109
150
|
- CODE_OF_CONDUCT.md
|
110
151
|
- Dockerfile
|
111
152
|
- Gemfile
|
@@ -116,6 +157,11 @@ files:
|
|
116
157
|
- bin/console
|
117
158
|
- bin/setup
|
118
159
|
- docker-compose.yml
|
160
|
+
- gemfiles/rails_5.1.gemfile
|
161
|
+
- gemfiles/rails_5.2.gemfile
|
162
|
+
- gemfiles/rails_6.0.gemfile
|
163
|
+
- gemfiles/rails_6.1.gemfile
|
164
|
+
- gemfiles/rails_7.0.gemfile
|
119
165
|
- lib/active_record/connection_adapters/abstract_mysql.rb
|
120
166
|
- lib/active_record/connection_adapters/mysql/column_methods.rb
|
121
167
|
- lib/active_record/connection_adapters/mysql2.rb
|
@@ -125,12 +171,15 @@ files:
|
|
125
171
|
- lib/sql_enum/class_methods.rb
|
126
172
|
- lib/sql_enum/configuration.rb
|
127
173
|
- lib/sql_enum/enum_column.rb
|
174
|
+
- lib/sql_enum/enum_type.rb
|
128
175
|
- lib/sql_enum/version.rb
|
129
176
|
- sql_enum.gemspec
|
130
177
|
homepage: https://github.com/1debit/sql_enum
|
131
178
|
licenses:
|
132
179
|
- MIT
|
133
|
-
metadata:
|
180
|
+
metadata:
|
181
|
+
homepage_uri: https://github.com/1debit/sql_enum
|
182
|
+
source_code_uri: https://github.com/1debit/sql_enum
|
134
183
|
post_install_message:
|
135
184
|
rdoc_options: []
|
136
185
|
require_paths:
|
@@ -146,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
195
|
- !ruby/object:Gem::Version
|
147
196
|
version: '0'
|
148
197
|
requirements: []
|
149
|
-
rubygems_version: 3.
|
198
|
+
rubygems_version: 3.1.6
|
150
199
|
signing_key:
|
151
200
|
specification_version: 4
|
152
201
|
summary: Enable using native sql enums
|