activerecord-mysql-enum 0.1.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/test.yml +39 -0
- data/.gitignore +6 -0
- data/.rspec +1 -0
- data/Appraisals +11 -0
- data/CHANGELOG.md +23 -0
- data/Gemfile +5 -2
- data/Gemfile.lock +139 -76
- data/README.md +3 -19
- data/Rakefile +15 -2
- data/app/assets/config/manifest.js +1 -0
- data/enum_column.gemspec +2 -1
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/rails_5.gemfile +15 -0
- data/gemfiles/rails_6.gemfile +15 -0
- data/lib/active_record/mysql/enum.rb +0 -5
- data/lib/active_record/mysql/enum/enum_column_adapter.rb +38 -91
- data/lib/active_record/mysql/enum/mysql_adapter.rb +25 -45
- data/lib/active_record/mysql/enum/quoting.rb +5 -15
- data/lib/active_record/mysql/enum/version.rb +1 -1
- data/lib/activerecord-mysql-enum.rb +1 -0
- metadata +36 -11
- data/lib/active_record/mysql/enum/active_record_helper.rb +0 -65
- data/lib/active_record/mysql/enum/enum_adapter.rb +0 -27
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 459885e4a5040ecec66b8e13a82810c5b58a516e7b6d862540861b983ec16671
|
|
4
|
+
data.tar.gz: 22dc3afd5d45bf3a5b7f6ca49105742ac805b9385e470983eaf38be9d22a58fb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '0219e9b653b15e4354b8e515ee815a7dd6daa99c7ccc88470017e3802096e739008ce985c67bfee9aa543f918a5a58a2a5d449c3b6f2dc00601c2412143f7df6'
|
|
7
|
+
data.tar.gz: 2215b573018c5d3971294b2d9a672434497437c5c9f846e1ee945491ab2629f03152da44bf0a55dfa91ea17bff3e44ed964655b39aab3d6eb5e5ca748c01f1c0
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ActiveRecord MySQL Enum
|
|
3
|
+
on: [push]
|
|
4
|
+
jobs:
|
|
5
|
+
test:
|
|
6
|
+
name: Unit Tests
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
services:
|
|
9
|
+
mysql:
|
|
10
|
+
image: mysql:5.7
|
|
11
|
+
env:
|
|
12
|
+
MYSQL_DATABASE: activerecord_mysql_enum_test
|
|
13
|
+
MYSQL_USER: user
|
|
14
|
+
MYSQL_PASSWORD: password
|
|
15
|
+
MYSQL_ROOT_PASSWORD: rootpassword
|
|
16
|
+
ports:
|
|
17
|
+
- 3306:3306
|
|
18
|
+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
|
|
19
|
+
strategy:
|
|
20
|
+
fail-fast: false
|
|
21
|
+
matrix:
|
|
22
|
+
ruby: [2.5.8, 2.6.5, 2.7.1]
|
|
23
|
+
gemfile:
|
|
24
|
+
- gemfiles/rails_5.gemfile
|
|
25
|
+
- gemfiles/rails_6.gemfile
|
|
26
|
+
env:
|
|
27
|
+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
|
28
|
+
DATABASE_MYSQL_HOST: 127.0.0.1
|
|
29
|
+
DATABASE_MYSQL_USERNAME: user
|
|
30
|
+
DATABASE_MYSQL_PASSWORD: password
|
|
31
|
+
steps:
|
|
32
|
+
- uses: actions/checkout@v2
|
|
33
|
+
- uses: ruby/setup-ruby@v1
|
|
34
|
+
with:
|
|
35
|
+
ruby-version: ${{ matrix.ruby }}
|
|
36
|
+
bundler: 1.17.3
|
|
37
|
+
bundler-cache: true
|
|
38
|
+
- run: RAILS_ENV=test bundle exec rake db:create
|
|
39
|
+
- run: bundle exec rspec
|
data/.gitignore
CHANGED
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--require rails_helper
|
data/Appraisals
ADDED
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,27 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
|
4
4
|
|
|
5
5
|
Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [2.0.0] - 2021-08-10
|
|
8
|
+
### Removed
|
|
9
|
+
- Dropped support for Rails less than 5
|
|
10
|
+
|
|
11
|
+
## [1.0.0] - 2020-09-16
|
|
12
|
+
### Added
|
|
13
|
+
- A Rspec test suit
|
|
14
|
+
- Dummy Rails app to be used by tests
|
|
15
|
+
- Test coverage reports via Coveralls/SimpleCov
|
|
16
|
+
- A coverage report badge to the README
|
|
17
|
+
- Unit tests being run on push with TravisCI
|
|
18
|
+
- Appraisal to test Rails 4.2, 5.2, and 6.0
|
|
19
|
+
- A dependency on the mysql2 gem
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- Existing tests to be run with Rspec
|
|
23
|
+
|
|
24
|
+
### Removed
|
|
25
|
+
- Support for the mysql gem
|
|
26
|
+
- Support for Rails < 4.2
|
|
27
|
+
|
|
7
28
|
## [0.1.4] - 2020-08-20
|
|
8
29
|
### Fixed
|
|
9
30
|
- Fixed bug in `mysql_adapter` where optional arguments being passed to `type_to_sql` would cause
|
|
@@ -28,6 +49,8 @@ Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0
|
|
|
28
49
|
### Changed
|
|
29
50
|
- Renamed the gem from `enum_column3` to `activerecord-mysql-enum`
|
|
30
51
|
|
|
52
|
+
[2.0.0]: https://github.com/Invoca/activerecord-mysql-enum/compare/v1.0.0...v2.0.0
|
|
53
|
+
[1.0.0]: https://github.com/Invoca/activerecord-mysql-enum/compare/v0.1.4...v1.0.0
|
|
31
54
|
[0.1.4]: https://github.com/Invoca/activerecord-mysql-enum/compare/v0.1.3...v0.1.4
|
|
32
55
|
[0.1.3]: https://github.com/Invoca/activerecord-mysql-enum/compare/v0.1.2...v0.1.3
|
|
33
56
|
[0.1.2]: https://github.com/Invoca/activerecord-mysql-enum/compare/v0.1.1...v0.1.2
|
data/Gemfile
CHANGED
|
@@ -5,8 +5,11 @@ source 'https://rubygems.org'
|
|
|
5
5
|
# Specify your gem's dependencies in active_table_set.gemspec
|
|
6
6
|
gemspec
|
|
7
7
|
|
|
8
|
-
gem '
|
|
8
|
+
gem 'appraisal'
|
|
9
|
+
gem 'coveralls', require: false
|
|
9
10
|
gem 'pry'
|
|
10
11
|
gem 'pry-byebug'
|
|
11
12
|
gem 'rake', '~> 13.0'
|
|
12
|
-
gem 'rails', '~>
|
|
13
|
+
gem 'rails', '~> 5.2'
|
|
14
|
+
gem 'rspec'
|
|
15
|
+
gem 'rspec-rails', '~> 3.0'
|
data/Gemfile.lock
CHANGED
|
@@ -1,124 +1,187 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
activerecord-mysql-enum (0.
|
|
5
|
-
activerecord (>=
|
|
4
|
+
activerecord-mysql-enum (2.0.0)
|
|
5
|
+
activerecord (>= 5.2, < 7)
|
|
6
|
+
mysql2 (>= 0.4.5, < 0.6)
|
|
6
7
|
|
|
7
8
|
GEM
|
|
8
9
|
remote: https://rubygems.org/
|
|
9
10
|
specs:
|
|
10
|
-
|
|
11
|
-
actionpack (=
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
actioncable (5.2.6)
|
|
12
|
+
actionpack (= 5.2.6)
|
|
13
|
+
nio4r (~> 2.0)
|
|
14
|
+
websocket-driver (>= 0.6.1)
|
|
15
|
+
actionmailer (5.2.6)
|
|
16
|
+
actionpack (= 5.2.6)
|
|
17
|
+
actionview (= 5.2.6)
|
|
18
|
+
activejob (= 5.2.6)
|
|
14
19
|
mail (~> 2.5, >= 2.5.4)
|
|
15
|
-
rails-dom-testing (~>
|
|
16
|
-
actionpack (
|
|
17
|
-
actionview (=
|
|
18
|
-
activesupport (=
|
|
19
|
-
rack (~>
|
|
20
|
-
rack-test (
|
|
21
|
-
rails-dom-testing (~>
|
|
20
|
+
rails-dom-testing (~> 2.0)
|
|
21
|
+
actionpack (5.2.6)
|
|
22
|
+
actionview (= 5.2.6)
|
|
23
|
+
activesupport (= 5.2.6)
|
|
24
|
+
rack (~> 2.0, >= 2.0.8)
|
|
25
|
+
rack-test (>= 0.6.3)
|
|
26
|
+
rails-dom-testing (~> 2.0)
|
|
22
27
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
23
|
-
actionview (
|
|
24
|
-
activesupport (=
|
|
28
|
+
actionview (5.2.6)
|
|
29
|
+
activesupport (= 5.2.6)
|
|
25
30
|
builder (~> 3.1)
|
|
26
|
-
|
|
27
|
-
rails-dom-testing (~>
|
|
31
|
+
erubi (~> 1.4)
|
|
32
|
+
rails-dom-testing (~> 2.0)
|
|
28
33
|
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
|
29
|
-
activejob (
|
|
30
|
-
activesupport (=
|
|
31
|
-
globalid (>= 0.3.
|
|
32
|
-
activemodel (
|
|
33
|
-
activesupport (=
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
activejob (5.2.6)
|
|
35
|
+
activesupport (= 5.2.6)
|
|
36
|
+
globalid (>= 0.3.6)
|
|
37
|
+
activemodel (5.2.6)
|
|
38
|
+
activesupport (= 5.2.6)
|
|
39
|
+
activerecord (5.2.6)
|
|
40
|
+
activemodel (= 5.2.6)
|
|
41
|
+
activesupport (= 5.2.6)
|
|
42
|
+
arel (>= 9.0)
|
|
43
|
+
activestorage (5.2.6)
|
|
44
|
+
actionpack (= 5.2.6)
|
|
45
|
+
activerecord (= 5.2.6)
|
|
46
|
+
marcel (~> 1.0.0)
|
|
47
|
+
activesupport (5.2.6)
|
|
48
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
49
|
+
i18n (>= 0.7, < 2)
|
|
41
50
|
minitest (~> 5.1)
|
|
42
|
-
thread_safe (~> 0.3, >= 0.3.4)
|
|
43
51
|
tzinfo (~> 1.1)
|
|
44
|
-
|
|
52
|
+
appraisal (2.4.1)
|
|
53
|
+
bundler
|
|
54
|
+
rake
|
|
55
|
+
thor (>= 0.14.0)
|
|
56
|
+
arel (9.0.0)
|
|
45
57
|
builder (3.2.4)
|
|
46
58
|
byebug (11.1.3)
|
|
47
59
|
coderay (1.1.3)
|
|
48
|
-
concurrent-ruby (1.1.
|
|
60
|
+
concurrent-ruby (1.1.9)
|
|
61
|
+
coveralls (0.8.23)
|
|
62
|
+
json (>= 1.8, < 3)
|
|
63
|
+
simplecov (~> 0.16.1)
|
|
64
|
+
term-ansicolor (~> 1.3)
|
|
65
|
+
thor (>= 0.19.4, < 2.0)
|
|
66
|
+
tins (~> 1.6)
|
|
49
67
|
crass (1.0.6)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
68
|
+
diff-lcs (1.4.4)
|
|
69
|
+
docile (1.4.0)
|
|
70
|
+
erubi (1.10.0)
|
|
71
|
+
globalid (0.5.2)
|
|
72
|
+
activesupport (>= 5.0)
|
|
73
|
+
i18n (1.8.10)
|
|
54
74
|
concurrent-ruby (~> 1.0)
|
|
55
|
-
|
|
75
|
+
json (2.5.1)
|
|
76
|
+
loofah (2.11.0)
|
|
56
77
|
crass (~> 1.0.2)
|
|
57
78
|
nokogiri (>= 1.5.9)
|
|
58
79
|
mail (2.7.1)
|
|
59
80
|
mini_mime (>= 0.1.1)
|
|
81
|
+
marcel (1.0.1)
|
|
60
82
|
method_source (1.0.0)
|
|
61
|
-
mini_mime (1.0
|
|
62
|
-
mini_portile2 (2.
|
|
63
|
-
minitest (5.14.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
83
|
+
mini_mime (1.1.0)
|
|
84
|
+
mini_portile2 (2.6.1)
|
|
85
|
+
minitest (5.14.4)
|
|
86
|
+
mysql2 (0.5.3)
|
|
87
|
+
nio4r (2.5.8)
|
|
88
|
+
nokogiri (1.12.2)
|
|
89
|
+
mini_portile2 (~> 2.6.1)
|
|
90
|
+
racc (~> 1.4)
|
|
91
|
+
pry (0.14.1)
|
|
67
92
|
coderay (~> 1.1)
|
|
68
93
|
method_source (~> 1.0)
|
|
69
|
-
pry-byebug (3.
|
|
94
|
+
pry-byebug (3.8.0)
|
|
70
95
|
byebug (~> 11.0)
|
|
71
|
-
pry (~> 0.
|
|
72
|
-
|
|
73
|
-
rack
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
pry (~> 0.10)
|
|
97
|
+
racc (1.5.2)
|
|
98
|
+
rack (2.2.3)
|
|
99
|
+
rack-test (1.1.0)
|
|
100
|
+
rack (>= 1.0, < 3)
|
|
101
|
+
rails (5.2.6)
|
|
102
|
+
actioncable (= 5.2.6)
|
|
103
|
+
actionmailer (= 5.2.6)
|
|
104
|
+
actionpack (= 5.2.6)
|
|
105
|
+
actionview (= 5.2.6)
|
|
106
|
+
activejob (= 5.2.6)
|
|
107
|
+
activemodel (= 5.2.6)
|
|
108
|
+
activerecord (= 5.2.6)
|
|
109
|
+
activestorage (= 5.2.6)
|
|
110
|
+
activesupport (= 5.2.6)
|
|
111
|
+
bundler (>= 1.3.0)
|
|
112
|
+
railties (= 5.2.6)
|
|
113
|
+
sprockets-rails (>= 2.0.0)
|
|
114
|
+
rails-dom-testing (2.0.3)
|
|
115
|
+
activesupport (>= 4.2.0)
|
|
116
|
+
nokogiri (>= 1.6)
|
|
92
117
|
rails-html-sanitizer (1.3.0)
|
|
93
118
|
loofah (~> 2.3)
|
|
94
|
-
railties (
|
|
95
|
-
actionpack (=
|
|
96
|
-
activesupport (=
|
|
119
|
+
railties (5.2.6)
|
|
120
|
+
actionpack (= 5.2.6)
|
|
121
|
+
activesupport (= 5.2.6)
|
|
122
|
+
method_source
|
|
97
123
|
rake (>= 0.8.7)
|
|
98
|
-
thor (>= 0.
|
|
99
|
-
rake (13.0.
|
|
100
|
-
|
|
124
|
+
thor (>= 0.19.0, < 2.0)
|
|
125
|
+
rake (13.0.6)
|
|
126
|
+
rspec (3.9.0)
|
|
127
|
+
rspec-core (~> 3.9.0)
|
|
128
|
+
rspec-expectations (~> 3.9.0)
|
|
129
|
+
rspec-mocks (~> 3.9.0)
|
|
130
|
+
rspec-core (3.9.3)
|
|
131
|
+
rspec-support (~> 3.9.3)
|
|
132
|
+
rspec-expectations (3.9.4)
|
|
133
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
134
|
+
rspec-support (~> 3.9.0)
|
|
135
|
+
rspec-mocks (3.9.1)
|
|
136
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
137
|
+
rspec-support (~> 3.9.0)
|
|
138
|
+
rspec-rails (3.9.1)
|
|
139
|
+
actionpack (>= 3.0)
|
|
140
|
+
activesupport (>= 3.0)
|
|
141
|
+
railties (>= 3.0)
|
|
142
|
+
rspec-core (~> 3.9.0)
|
|
143
|
+
rspec-expectations (~> 3.9.0)
|
|
144
|
+
rspec-mocks (~> 3.9.0)
|
|
145
|
+
rspec-support (~> 3.9.0)
|
|
146
|
+
rspec-support (3.9.4)
|
|
147
|
+
simplecov (0.16.1)
|
|
148
|
+
docile (~> 1.1)
|
|
149
|
+
json (>= 1.8, < 3)
|
|
150
|
+
simplecov-html (~> 0.10.0)
|
|
151
|
+
simplecov-html (0.10.2)
|
|
152
|
+
sprockets (4.0.2)
|
|
101
153
|
concurrent-ruby (~> 1.0)
|
|
102
154
|
rack (> 1, < 3)
|
|
103
|
-
sprockets-rails (3.2.
|
|
155
|
+
sprockets-rails (3.2.2)
|
|
104
156
|
actionpack (>= 4.0)
|
|
105
157
|
activesupport (>= 4.0)
|
|
106
158
|
sprockets (>= 3.0.0)
|
|
107
|
-
|
|
159
|
+
sync (0.5.0)
|
|
160
|
+
term-ansicolor (1.7.1)
|
|
161
|
+
tins (~> 1.0)
|
|
162
|
+
thor (1.1.0)
|
|
108
163
|
thread_safe (0.3.6)
|
|
109
|
-
|
|
164
|
+
tins (1.29.1)
|
|
165
|
+
sync
|
|
166
|
+
tzinfo (1.2.9)
|
|
110
167
|
thread_safe (~> 0.1)
|
|
168
|
+
websocket-driver (0.7.5)
|
|
169
|
+
websocket-extensions (>= 0.1.0)
|
|
170
|
+
websocket-extensions (0.1.5)
|
|
111
171
|
|
|
112
172
|
PLATFORMS
|
|
113
173
|
ruby
|
|
114
174
|
|
|
115
175
|
DEPENDENCIES
|
|
116
176
|
activerecord-mysql-enum!
|
|
117
|
-
|
|
177
|
+
appraisal
|
|
178
|
+
coveralls
|
|
118
179
|
pry
|
|
119
180
|
pry-byebug
|
|
120
|
-
rails (~>
|
|
181
|
+
rails (~> 5.2)
|
|
121
182
|
rake (~> 13.0)
|
|
183
|
+
rspec
|
|
184
|
+
rspec-rails (~> 3.0)
|
|
122
185
|
|
|
123
186
|
BUNDLED WITH
|
|
124
187
|
1.17.3
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# ActiveRecord::Mysql::Enum
|
|
1
|
+
# ActiveRecord::Mysql::Enum [](https://coveralls.io/github/Invoca/activerecord-mysql-enum?branch=master)
|
|
2
2
|
|
|
3
3
|
This gem is an extension to ActiveRecord which enables native support of
|
|
4
4
|
enumerations in the database schema using the ENUM type in MySQL. Forked
|
|
@@ -7,17 +7,15 @@ which was itself a fork of a fork of Nick Pohodnya's original gem for
|
|
|
7
7
|
Rails 3, [enum_column3](https://github.com/electronick/enum_column).
|
|
8
8
|
|
|
9
9
|
## Support
|
|
10
|
-
Currently this
|
|
10
|
+
Currently this is tested with Rails version 5.2, and 6.0.
|
|
11
11
|
|
|
12
12
|
**Supported adapters:**
|
|
13
|
-
- mysql
|
|
14
13
|
- mysql2
|
|
15
|
-
- jdbcmysql (by Nilesh Trivedi)
|
|
16
14
|
|
|
17
15
|
## Installation
|
|
18
16
|
In your `Gemfile` add the following snippet
|
|
19
17
|
```ruby
|
|
20
|
-
gem 'activerecord-mysql-enum', '~> 0
|
|
18
|
+
gem 'activerecord-mysql-enum', '~> 1.0', require: 'active_record/mysql/enum'
|
|
21
19
|
```
|
|
22
20
|
|
|
23
21
|
## Usage
|
|
@@ -50,17 +48,3 @@ irb(1)> Enumeration.columns_hash['color'].limit
|
|
|
50
48
|
irb(2)> @enumeration.column_for_attribute(:color).limit
|
|
51
49
|
=> [:red, :blue, :green, :yellow]
|
|
52
50
|
```
|
|
53
|
-
|
|
54
|
-
### Form Helpers
|
|
55
|
-
You can use enum_select helper to generate input for enumerated attribute as:
|
|
56
|
-
```ruby
|
|
57
|
-
<%= enum_select(@enumeration, 'severity')%>
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
Or using `form_for`:
|
|
61
|
-
```ruby
|
|
62
|
-
<%= form_for @enumeration do |f| %>
|
|
63
|
-
<%= f.label :severity %>
|
|
64
|
-
<%= f.enum_select :severity %>
|
|
65
|
-
<% end %>
|
|
66
|
-
```
|
data/Rakefile
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
#
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
|
3
|
+
require File.expand_path('../spec/dummy/config/application', __FILE__)
|
|
4
|
+
Rails.application.config.root = "spec/dummy"
|
|
3
5
|
|
|
4
6
|
Bundler::GemHelper.install_tasks
|
|
7
|
+
Rails.application.load_tasks
|
|
8
|
+
|
|
9
|
+
task default: :rspec
|
|
10
|
+
|
|
11
|
+
desc "run rspec unit tests"
|
|
12
|
+
begin
|
|
13
|
+
require 'rspec/core/rake_task'
|
|
14
|
+
RSpec::Core::RakeTask.new(:rspec) do |rspec_task|
|
|
15
|
+
# rspec_task.exclude_pattern = 'spec/e2e/**/*_spec.rb'
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
data/enum_column.gemspec
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# This file was generated by Appraisal
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
gem "appraisal"
|
|
6
|
+
gem "coveralls", require: false
|
|
7
|
+
gem "pry"
|
|
8
|
+
gem "pry-byebug"
|
|
9
|
+
gem "rake", "~> 13.0"
|
|
10
|
+
gem "rails", "~> 5.2"
|
|
11
|
+
gem "rspec"
|
|
12
|
+
gem "rspec-rails", "~> 3.0"
|
|
13
|
+
gem "mysql2", "~> 0.4"
|
|
14
|
+
|
|
15
|
+
gemspec path: "../"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# This file was generated by Appraisal
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
gem "appraisal"
|
|
6
|
+
gem "coveralls", require: false
|
|
7
|
+
gem "pry"
|
|
8
|
+
gem "pry-byebug"
|
|
9
|
+
gem "rake", "~> 13.0"
|
|
10
|
+
gem "rails", "~> 6.0.0"
|
|
11
|
+
gem "rspec"
|
|
12
|
+
gem "rspec-rails", "~> 3.0"
|
|
13
|
+
gem "mysql2", "~> 0.5"
|
|
14
|
+
|
|
15
|
+
gemspec path: "../"
|
|
@@ -9,16 +9,11 @@ if defined?(::Rails::Railtie)
|
|
|
9
9
|
ActiveSupport.on_load :active_record do
|
|
10
10
|
require 'active_record/mysql/enum/mysql_adapter'
|
|
11
11
|
require 'active_record/mysql/enum/enum_type'
|
|
12
|
-
require 'active_record/mysql/enum/enum_adapter'
|
|
13
12
|
require 'active_record/mysql/enum/enum_column_adapter'
|
|
14
13
|
require 'active_record/mysql/enum/schema_definitions'
|
|
15
14
|
require 'active_record/mysql/enum/quoting'
|
|
16
15
|
require 'active_record/mysql/enum/validations'
|
|
17
16
|
end
|
|
18
|
-
|
|
19
|
-
ActiveSupport.on_load :action_view do
|
|
20
|
-
require 'active_record/mysql/enum/active_record_helper'
|
|
21
|
-
end
|
|
22
17
|
end
|
|
23
18
|
end
|
|
24
19
|
end
|
|
@@ -3,111 +3,58 @@
|
|
|
3
3
|
# This module provides all the column helper methods to deal with the
|
|
4
4
|
# values and adds the common type management code for the adapters.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
elsif defined? ActiveRecord::ConnectionAdapters::
|
|
15
|
-
|
|
16
|
-
elsif defined? ActiveRecord::ConnectionAdapters::MySQL::Column
|
|
17
|
-
ActiveRecord::ConnectionAdapters::MySQL::Column
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
if column_class
|
|
21
|
-
column_class.class_eval do
|
|
22
|
-
|
|
23
|
-
if instance_methods.include?(:extract_default)
|
|
24
|
-
alias __extract_default_enum extract_default
|
|
25
|
-
def extract_default
|
|
26
|
-
if type == :enum
|
|
27
|
-
if @default == '' || @default.nil?
|
|
28
|
-
@default = nil
|
|
6
|
+
module ActiveRecord
|
|
7
|
+
module Mysql
|
|
8
|
+
module Enum
|
|
9
|
+
|
|
10
|
+
class << self
|
|
11
|
+
def mysql_column_adapter
|
|
12
|
+
if defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter::Column
|
|
13
|
+
ActiveRecord::ConnectionAdapters::Mysql2Adapter::Column
|
|
14
|
+
elsif defined? ActiveRecord::ConnectionAdapters::MySQL::Column
|
|
15
|
+
ActiveRecord::ConnectionAdapters::MySQL::Column
|
|
29
16
|
else
|
|
30
|
-
|
|
17
|
+
raise "could not find MySQL::Column or equivalent connection adapter"
|
|
31
18
|
end
|
|
32
19
|
end
|
|
33
|
-
__extract_default_enum
|
|
34
20
|
end
|
|
35
|
-
end
|
|
36
21
|
|
|
37
|
-
|
|
38
|
-
if type == :enum
|
|
39
|
-
self.class.value_to_symbol(value)
|
|
40
|
-
else
|
|
41
|
-
__type_cast_enum(value)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
22
|
+
ActiveRecordColumnWithEnums = Enum.mysql_column_adapter
|
|
44
23
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def type_cast_from_database(value)
|
|
49
|
-
__enum_type_cast(value)
|
|
50
|
-
end
|
|
51
|
-
elsif instance_methods.include?(:type_cast)
|
|
52
|
-
alias __type_cast_enum type_cast
|
|
53
|
-
def type_cast(value)
|
|
54
|
-
__enum_type_cast(value)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
24
|
+
module EnumColumnAdapter
|
|
25
|
+
def initialize(*)
|
|
26
|
+
super
|
|
57
27
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if type == :enum
|
|
64
|
-
"#{self.class.name}.value_to_symbol(#{var_name})"
|
|
65
|
-
else
|
|
66
|
-
__type_cast_code_enum(var_name)
|
|
28
|
+
if type == :enum
|
|
29
|
+
@default = if @default.present?
|
|
30
|
+
@default.to_sym
|
|
31
|
+
end
|
|
32
|
+
end
|
|
67
33
|
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
34
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
value.empty? ? nil : value.intern
|
|
79
|
-
else
|
|
80
|
-
nil
|
|
35
|
+
# Convert to a symbol.
|
|
36
|
+
def type_cast_from_database(value)
|
|
37
|
+
if type == :enum
|
|
38
|
+
EnumColumnAdapter.value_to_symbol(value)
|
|
39
|
+
else
|
|
40
|
+
super
|
|
41
|
+
end
|
|
81
42
|
end
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
private
|
|
86
43
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
44
|
+
class << self
|
|
45
|
+
# Safely convert the value to a symbol.
|
|
46
|
+
def value_to_symbol(value)
|
|
47
|
+
case value
|
|
48
|
+
when Symbol
|
|
49
|
+
value
|
|
50
|
+
when String
|
|
51
|
+
value.to_sym if value.present?
|
|
52
|
+
end
|
|
53
|
+
end
|
|
96
54
|
end
|
|
97
55
|
end
|
|
98
|
-
end
|
|
99
56
|
|
|
100
|
-
|
|
101
|
-
if private_instance_methods.include?(:extract_limit)
|
|
102
|
-
alias __extract_limit_enum extract_limit
|
|
103
|
-
def extract_limit(sql_type)
|
|
104
|
-
if sql_type =~ /^enum/i
|
|
105
|
-
sql_type.sub(/^enum\('(.+)'\)/i, '\1').split("','").map { |v| v.intern }
|
|
106
|
-
else
|
|
107
|
-
__extract_limit_enum(sql_type)
|
|
108
|
-
end
|
|
109
|
-
end
|
|
57
|
+
ActiveRecordColumnWithEnums.prepend EnumColumnAdapter
|
|
110
58
|
end
|
|
111
|
-
|
|
112
59
|
end
|
|
113
60
|
end
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
adapter_class = if defined? ActiveRecord::ConnectionAdapters::MySQLJdbcConnection
|
|
4
|
-
ActiveRecord::ConnectionAdapters::MySQLJdbcConnection
|
|
5
|
-
# elsif defined? ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter
|
|
6
|
-
# ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter
|
|
7
|
-
elsif defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
|
8
|
-
ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
|
9
|
-
elsif defined? ActiveRecord::ConnectionAdapters::MysqlAdapter
|
|
10
|
-
ActiveRecord::ConnectionAdapters::MysqlAdapter
|
|
11
|
-
end
|
|
12
|
-
|
|
13
3
|
module ActiveRecord
|
|
14
4
|
module Mysql
|
|
15
5
|
module Enum
|
|
6
|
+
|
|
7
|
+
class << self
|
|
8
|
+
def mysql_adapter
|
|
9
|
+
defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter or raise "Could not find MySQL connection adapter"
|
|
10
|
+
|
|
11
|
+
ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
ActiveRecordMysqlAdapter = Enum.mysql_adapter
|
|
16
|
+
|
|
16
17
|
module MysqlAdapter
|
|
17
18
|
def native_database_types #:nodoc
|
|
18
19
|
types = super
|
|
@@ -27,39 +28,20 @@ module ActiveRecord
|
|
|
27
28
|
# be done on a per adapter basis, but is generalized here.
|
|
28
29
|
#
|
|
29
30
|
# will generate enum('a', 'b', 'c') for :limit => [:a, :b, :c]
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
quoted_values = limit.map { |v| quote(v) }.join(',')
|
|
41
|
-
|
|
42
|
-
"#{column_type_sql}(#{quoted_values})"
|
|
43
|
-
else
|
|
44
|
-
super
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
else
|
|
48
|
-
def type_to_sql(type, limit: nil, **_options) # :nodoc:
|
|
49
|
-
if type.to_s == 'enum'
|
|
50
|
-
column_type_sql =
|
|
51
|
-
if (native_database_type = native_database_types[type])
|
|
52
|
-
native_database_type[:name]
|
|
53
|
-
else
|
|
54
|
-
'enum'
|
|
55
|
-
end
|
|
31
|
+
def type_to_sql(type, limit: nil, **_options) # :nodoc:
|
|
32
|
+
if type.to_s == 'enum'
|
|
33
|
+
column_type_sql =
|
|
34
|
+
if (native_database_type = native_database_types[type])
|
|
35
|
+
native_database_type[:name]
|
|
36
|
+
else
|
|
37
|
+
'enum'
|
|
38
|
+
end
|
|
56
39
|
|
|
57
|
-
|
|
40
|
+
quoted_values = limit.map { |v| quote(v) }.join(',')
|
|
58
41
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
end
|
|
42
|
+
"#{column_type_sql}(#{quoted_values})"
|
|
43
|
+
else
|
|
44
|
+
super
|
|
63
45
|
end
|
|
64
46
|
end
|
|
65
47
|
|
|
@@ -75,10 +57,8 @@ module ActiveRecord
|
|
|
75
57
|
end
|
|
76
58
|
end
|
|
77
59
|
end
|
|
60
|
+
|
|
61
|
+
ActiveRecordMysqlAdapter.prepend ActiveRecord::Mysql::Enum::MysqlAdapter
|
|
78
62
|
end
|
|
79
63
|
end
|
|
80
64
|
end
|
|
81
|
-
|
|
82
|
-
if adapter_class
|
|
83
|
-
adapter_class.prepend(ActiveRecord::Mysql::Enum::MysqlAdapter)
|
|
84
|
-
end
|
|
@@ -7,21 +7,11 @@ module ActiveRecord
|
|
|
7
7
|
|
|
8
8
|
# Quote a symbol as a normal string. This will support quoting of
|
|
9
9
|
# enumerated values.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
ActiveRecord::Base.send(:quote_bound_value, value.to_s)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
else
|
|
19
|
-
def quote(value)
|
|
20
|
-
if !value.is_a? Symbol
|
|
21
|
-
__quote_enum(value)
|
|
22
|
-
else
|
|
23
|
-
ActiveRecord::Base.send(:quote_bound_value, value.to_s)
|
|
24
|
-
end
|
|
10
|
+
def quote(value)
|
|
11
|
+
if !value.is_a? Symbol
|
|
12
|
+
__quote_enum(value)
|
|
13
|
+
else
|
|
14
|
+
ActiveRecord::Base.send(:quote_bound_value, value.to_s)
|
|
25
15
|
end
|
|
26
16
|
end
|
|
27
17
|
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'active_record/mysql/enum'
|
metadata
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activerecord-mysql-enum
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nick Pohodnya
|
|
8
8
|
- Invoca Development
|
|
9
|
-
autorequire:
|
|
9
|
+
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2021-08-10 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activerecord
|
|
@@ -17,7 +17,7 @@ dependencies:
|
|
|
17
17
|
requirements:
|
|
18
18
|
- - ">="
|
|
19
19
|
- !ruby/object:Gem::Version
|
|
20
|
-
version: '
|
|
20
|
+
version: '5.2'
|
|
21
21
|
- - "<"
|
|
22
22
|
- !ruby/object:Gem::Version
|
|
23
23
|
version: '7'
|
|
@@ -27,10 +27,30 @@ dependencies:
|
|
|
27
27
|
requirements:
|
|
28
28
|
- - ">="
|
|
29
29
|
- !ruby/object:Gem::Version
|
|
30
|
-
version: '
|
|
30
|
+
version: '5.2'
|
|
31
31
|
- - "<"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
33
|
version: '7'
|
|
34
|
+
- !ruby/object:Gem::Dependency
|
|
35
|
+
name: mysql2
|
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 0.4.5
|
|
41
|
+
- - "<"
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0.6'
|
|
44
|
+
type: :runtime
|
|
45
|
+
prerelease: false
|
|
46
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
47
|
+
requirements:
|
|
48
|
+
- - ">="
|
|
49
|
+
- !ruby/object:Gem::Version
|
|
50
|
+
version: 0.4.5
|
|
51
|
+
- - "<"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0.6'
|
|
34
54
|
description: Enable enum type for the MySQL Adapter in ActiveRecord
|
|
35
55
|
email:
|
|
36
56
|
- development@invoca.com
|
|
@@ -40,18 +60,23 @@ extra_rdoc_files: []
|
|
|
40
60
|
files:
|
|
41
61
|
- ".dependabot/config.yml"
|
|
42
62
|
- ".github/workflows/gem_release.yml"
|
|
63
|
+
- ".github/workflows/test.yml"
|
|
43
64
|
- ".gitignore"
|
|
65
|
+
- ".rspec"
|
|
66
|
+
- Appraisals
|
|
44
67
|
- CHANGELOG.md
|
|
45
68
|
- Gemfile
|
|
46
69
|
- Gemfile.lock
|
|
47
70
|
- LICENSE
|
|
48
71
|
- README.md
|
|
49
72
|
- Rakefile
|
|
73
|
+
- app/assets/config/manifest.js
|
|
50
74
|
- enum_column.gemspec
|
|
75
|
+
- gemfiles/.bundle/config
|
|
76
|
+
- gemfiles/rails_5.gemfile
|
|
77
|
+
- gemfiles/rails_6.gemfile
|
|
51
78
|
- init.rb
|
|
52
79
|
- lib/active_record/mysql/enum.rb
|
|
53
|
-
- lib/active_record/mysql/enum/active_record_helper.rb
|
|
54
|
-
- lib/active_record/mysql/enum/enum_adapter.rb
|
|
55
80
|
- lib/active_record/mysql/enum/enum_column_adapter.rb
|
|
56
81
|
- lib/active_record/mysql/enum/enum_type.rb
|
|
57
82
|
- lib/active_record/mysql/enum/mysql_adapter.rb
|
|
@@ -59,13 +84,14 @@ files:
|
|
|
59
84
|
- lib/active_record/mysql/enum/schema_definitions.rb
|
|
60
85
|
- lib/active_record/mysql/enum/validations.rb
|
|
61
86
|
- lib/active_record/mysql/enum/version.rb
|
|
87
|
+
- lib/activerecord-mysql-enum.rb
|
|
62
88
|
- rails/init.rb
|
|
63
89
|
homepage: http://github.com/Invoca/activerecord-mysql-enum
|
|
64
90
|
licenses: []
|
|
65
91
|
metadata:
|
|
66
92
|
source_code_uri: https://github.com/Invoca/activerecord-mysql-enum
|
|
67
93
|
allowed_push_host: https://rubygems.org
|
|
68
|
-
post_install_message:
|
|
94
|
+
post_install_message:
|
|
69
95
|
rdoc_options: []
|
|
70
96
|
require_paths:
|
|
71
97
|
- lib
|
|
@@ -80,9 +106,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
80
106
|
- !ruby/object:Gem::Version
|
|
81
107
|
version: '0'
|
|
82
108
|
requirements: []
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
signing_key:
|
|
109
|
+
rubygems_version: 3.0.1
|
|
110
|
+
signing_key:
|
|
86
111
|
specification_version: 4
|
|
87
112
|
summary: Enable enum type for the MySQL Adapter in ActiveRecord
|
|
88
113
|
test_files: []
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
if defined?(Rails::Generator)
|
|
4
|
-
module Rails
|
|
5
|
-
module Generator
|
|
6
|
-
class GeneratedAttribute
|
|
7
|
-
def field_type_with_enumerated_attribute
|
|
8
|
-
return (@field_type = :enum_select) if type == :enum
|
|
9
|
-
field_type_without_enumerated_attribute
|
|
10
|
-
end
|
|
11
|
-
alias_method_chain :field_type, :enumerated_attribute
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
if defined?(ActionView::Base)
|
|
18
|
-
module ActionView
|
|
19
|
-
module Helpers
|
|
20
|
-
|
|
21
|
-
#form_options_helper.rb
|
|
22
|
-
module FormOptionsHelper
|
|
23
|
-
#def select
|
|
24
|
-
def enum_select(object, method, options={}, html_options={})
|
|
25
|
-
InstanceTag.new(object, method, self, options.delete(:object)).to_enum_select_tag(options, html_options)
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
class InstanceTag
|
|
30
|
-
def to_enum_select_tag(options, html_options={})
|
|
31
|
-
if self.object.respond_to?(method_name.to_sym)
|
|
32
|
-
column = self.object.column_for_attribute(method_name)
|
|
33
|
-
if (value = self.object.__send__(method_name.to_sym))
|
|
34
|
-
options[:selected] ||= value.to_s
|
|
35
|
-
else
|
|
36
|
-
options[:include_blank] = column.null if options[:include_blank].nil?
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
to_select_tag(column.limit, options, html_options)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
#initialize record_name, method, self
|
|
43
|
-
if respond_to?(:to_tag)
|
|
44
|
-
def to_tag_with_enumerated_attribute(options={})
|
|
45
|
-
#look for an enum
|
|
46
|
-
if (column_type == :enum && self.object.class.respond_to?(method_name.to_sym))
|
|
47
|
-
to_enum_select_tag(options)
|
|
48
|
-
else
|
|
49
|
-
to_tag_without_enumerated_attribute(options)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
alias_method_chain :to_tag, :enumerated_attribute
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
class FormBuilder
|
|
58
|
-
def enum_select(method, options={}, html_options={})
|
|
59
|
-
@template.enum_select(@object_name, method, objectify_options(options), @default_options.merge(html_options))
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# This module provides all the column helper methods to deal with the
|
|
4
|
-
# values and adds the common type management code for the adapters.
|
|
5
|
-
|
|
6
|
-
adapter_class = if defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
|
7
|
-
ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
|
8
|
-
elsif defined? ActiveRecord::ConnectionAdapters::MysqlAdapter
|
|
9
|
-
ActiveRecord::ConnectionAdapters::MysqlAdapter
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
if adapter_class
|
|
13
|
-
adapter_class.class_eval do
|
|
14
|
-
|
|
15
|
-
protected
|
|
16
|
-
if instance_methods.include?(:initialize_type_map)
|
|
17
|
-
def initialize_type_map_with_enum_types(m)
|
|
18
|
-
initialize_type_map_without_enum_types(m)
|
|
19
|
-
m.register_type(%r(enum)i) do |sql_type|
|
|
20
|
-
limit = sql_type.sub(/^enum\('(.+)'\)/i, '\1').split("','").map { |v| v.intern }
|
|
21
|
-
ActiveRecord::Type::Enum.new(limit: limit)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
alias_method_chain :initialize_type_map, :enum_types
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|