activerecord-mysql-enum 0.1.4 → 1.0.0.pre.1

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.
Files changed (65) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +5 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +29 -0
  5. data/Appraisals +13 -0
  6. data/CHANGELOG.md +19 -1
  7. data/Gemfile +4 -1
  8. data/Gemfile.lock +51 -2
  9. data/README.md +3 -19
  10. data/Rakefile +15 -2
  11. data/app/assets/config/manifest.js +0 -0
  12. data/app/assets/images/.keep +0 -0
  13. data/app/assets/javascripts/application.js +16 -0
  14. data/app/assets/stylesheets/application.css +15 -0
  15. data/app/controllers/application_controller.rb +5 -0
  16. data/app/controllers/concerns/.keep +0 -0
  17. data/app/helpers/application_helper.rb +2 -0
  18. data/app/mailers/.keep +0 -0
  19. data/app/models/.keep +0 -0
  20. data/app/models/concerns/.keep +0 -0
  21. data/app/views/layouts/application.html.erb +14 -0
  22. data/bin/bundle +3 -0
  23. data/bin/rails +4 -0
  24. data/bin/rake +4 -0
  25. data/bin/setup +29 -0
  26. data/config/application.rb +35 -0
  27. data/config/boot.rb +3 -0
  28. data/config/database.yml +19 -0
  29. data/config/environment.rb +5 -0
  30. data/config/environments/development.rb +41 -0
  31. data/config/environments/production.rb +79 -0
  32. data/config/environments/test.rb +42 -0
  33. data/config/initializers/assets.rb +11 -0
  34. data/config/initializers/backtrace_silencers.rb +7 -0
  35. data/config/initializers/cookies_serializer.rb +3 -0
  36. data/config/initializers/filter_parameter_logging.rb +4 -0
  37. data/config/initializers/inflections.rb +16 -0
  38. data/config/initializers/mime_types.rb +4 -0
  39. data/config/initializers/session_store.rb +3 -0
  40. data/config/initializers/to_time_preserves_timezone.rb +10 -0
  41. data/config/initializers/wrap_parameters.rb +14 -0
  42. data/config/locales/en.yml +23 -0
  43. data/config/routes.rb +56 -0
  44. data/config/secrets.yml +22 -0
  45. data/db/schema.rb +26 -0
  46. data/db/seeds.rb +7 -0
  47. data/enum_column.gemspec +1 -0
  48. data/gemfiles/.bundle/config +2 -0
  49. data/gemfiles/rails_4.gemfile +14 -0
  50. data/gemfiles/rails_5.gemfile +14 -0
  51. data/gemfiles/rails_6.gemfile +14 -0
  52. data/lib/active_record/mysql/enum.rb +0 -5
  53. data/lib/active_record/mysql/enum/enum_column_adapter.rb +38 -91
  54. data/lib/active_record/mysql/enum/mysql_adapter.rb +15 -14
  55. data/lib/active_record/mysql/enum/version.rb +1 -1
  56. data/lib/activerecord-mysql-enum.rb +1 -0
  57. data/log/.keep +0 -0
  58. data/public/404.html +67 -0
  59. data/public/422.html +67 -0
  60. data/public/500.html +66 -0
  61. data/public/favicon.ico +0 -0
  62. data/public/robots.txt +5 -0
  63. metadata +72 -11
  64. data/lib/active_record/mysql/enum/active_record_helper.rb +0 -65
  65. data/lib/active_record/mysql/enum/enum_adapter.rb +0 -27
@@ -0,0 +1,14 @@
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
+
14
+ gemspec path: "../"
@@ -0,0 +1,14 @@
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"
11
+ gem "rspec"
12
+ gem "rspec-rails", "~> 3.0"
13
+
14
+ 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
- # try rails 3.1, then rails 3.2+, mysql column adapters
8
- column_class = if defined? ActiveRecord::ConnectionAdapters::Mysql2Column
9
- ActiveRecord::ConnectionAdapters::Mysql2Column
10
- elsif defined? ActiveRecord::ConnectionAdapters::MysqlColumn
11
- ActiveRecord::ConnectionAdapters::MysqlColumn
12
- elsif defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter::Column
13
- ActiveRecord::ConnectionAdapters::Mysql2Adapter::Column
14
- elsif defined? ActiveRecord::ConnectionAdapters::MysqlAdapter::Column
15
- ActiveRecord::ConnectionAdapters::MysqlAdapter::Column
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 current_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
- @default = @default.intern
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
- def __enum_type_cast(value)
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.current_mysql_column_adapter
44
23
 
45
- if instance_methods.include?(:type_cast_from_database)
46
- alias __type_cast_enum type_cast_from_database
47
- # Convert to a symbol.
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
- # Deprecated in Rails 4.1
59
- if instance_methods.include?(:type_cast_code)
60
- alias __type_cast_code_enum type_cast_code
61
- # Code to convert to a symbol.
62
- def type_cast_code(var_name)
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
- class << self
72
- # Safely convert the value to a symbol.
73
- def value_to_symbol(value)
74
- case value
75
- when Symbol
76
- value
77
- when String
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
- # Deprecated in Rails 4.2
88
- if private_instance_methods.include?(:simplified_type)
89
- alias __simplified_type_enum simplified_type
90
- # The enum simple type.
91
- def simplified_type(field_type)
92
- if field_type =~ /enum/i
93
- :enum
94
- else
95
- __simplified_type_enum(field_type)
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
- # Deprecated in Rails 4.2
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,21 @@
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 current_mysql_adapter
9
+ if defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter
10
+ ActiveRecord::ConnectionAdapters::Mysql2Adapter
11
+ else
12
+ raise "Could not find MySQL connection adapter"
13
+ end
14
+ end
15
+ end
16
+
17
+ ActiveRecordMysqlAdapter = Enum.current_mysql_adapter
18
+
16
19
  module MysqlAdapter
17
20
  def native_database_types #:nodoc
18
21
  types = super
@@ -75,10 +78,8 @@ module ActiveRecord
75
78
  end
76
79
  end
77
80
  end
81
+
82
+ ActiveRecordMysqlAdapter.prepend ActiveRecord::Mysql::Enum::MysqlAdapter
78
83
  end
79
84
  end
80
85
  end
81
-
82
- if adapter_class
83
- adapter_class.prepend(ActiveRecord::Mysql::Enum::MysqlAdapter)
84
- end
@@ -3,7 +3,7 @@
3
3
  module ActiveRecord
4
4
  module Mysql
5
5
  module Enum
6
- VERSION = "0.1.4"
6
+ VERSION = "1.0.0.pre.1"
7
7
  end
8
8
  end
9
9
  end
@@ -0,0 +1 @@
1
+ require 'active_record/mysql/enum'
File without changes
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>