Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .dependabot/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
version: 1
update_configs:
- package_manager: "ruby:bundler"
directory: "/"
update_schedule: "live"
version_requirement_updates: "off"
commit_message:
prefix: "No-Jira"
include_scope: true
38 changes: 38 additions & 0 deletions .github/workflows/gem_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
on:
push:
tags:
- 'v*'
- '!v*.pre*'

name: Create Release

jobs:
build:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Get version from tag
id: tag_name
shell: bash
run: |
echo ::set-output name=current_version::${GITHUB_REF#refs/tags/v}
- name: Checkout code
uses: actions/checkout@v2
- name: Get Changelog Entry
id: changelog_reader
uses: mindsers/changelog-reader-action@v1
with:
version: ${{ steps.tag_name.outputs.current_version }}
path: ./CHANGELOG.md
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GEM_RELEASE_GIT_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: ${{ steps.changelog_reader.outputs.log_entry }}
draft: false
prerelease: false
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.0] - Unreleased
### Added
- Backwards compatibility with Rails 4

### Changed
- Renamed the gem from `enum_column3` to `activerecord-mysql-enum`

Expand Down
12 changes: 12 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in active_table_set.gemspec
gemspec

gem 'bundler', '~> 1.8'
gem 'pry'
gem 'pry-byebug'
gem 'rake', '~> 13.0'
gem 'rails', '~> 4.2'
124 changes: 124 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
PATH
remote: .
specs:
activerecord-mysql-enum (0.1.0.pre.1)
activerecord (>= 4.2, < 6)

GEM
remote: https://rubygems.org/
specs:
actionmailer (4.2.11.3)
actionpack (= 4.2.11.3)
actionview (= 4.2.11.3)
activejob (= 4.2.11.3)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (4.2.11.3)
actionview (= 4.2.11.3)
activesupport (= 4.2.11.3)
rack (~> 1.6)
rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (4.2.11.3)
activesupport (= 4.2.11.3)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (4.2.11.3)
activesupport (= 4.2.11.3)
globalid (>= 0.3.0)
activemodel (4.2.11.3)
activesupport (= 4.2.11.3)
builder (~> 3.1)
activerecord (4.2.11.3)
activemodel (= 4.2.11.3)
activesupport (= 4.2.11.3)
arel (~> 6.0)
activesupport (4.2.11.3)
i18n (~> 0.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.4)
builder (3.2.4)
byebug (11.1.3)
coderay (1.1.3)
concurrent-ruby (1.1.7)
crass (1.0.6)
erubis (2.7.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
loofah (2.6.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
method_source (1.0.0)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.14.1)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
pry (0.13.1)
coderay (~> 1.1)
method_source (~> 1.0)
pry-byebug (3.9.0)
byebug (~> 11.0)
pry (~> 0.13.0)
rack (1.6.13)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.11.3)
actionmailer (= 4.2.11.3)
actionpack (= 4.2.11.3)
actionview (= 4.2.11.3)
activejob (= 4.2.11.3)
activemodel (= 4.2.11.3)
activerecord (= 4.2.11.3)
activesupport (= 4.2.11.3)
bundler (>= 1.3.0, < 2.0)
railties (= 4.2.11.3)
sprockets-rails
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.9)
activesupport (>= 4.2.0, < 5.0)
nokogiri (~> 1.6)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.3.0)
loofah (~> 2.3)
railties (4.2.11.3)
actionpack (= 4.2.11.3)
activesupport (= 4.2.11.3)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (13.0.1)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
thor (1.0.1)
thread_safe (0.3.6)
tzinfo (1.2.7)
thread_safe (~> 0.1)

PLATFORMS
ruby

DEPENDENCIES
activerecord-mysql-enum!
bundler (~> 1.8)
pry
pry-byebug
rails (~> 4.2)
rake (~> 13.0)

BUNDLED WITH
1.17.3
4 changes: 4 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env rake
# frozen_string_literal: true

Bundler::GemHelper.install_tasks
9 changes: 1 addition & 8 deletions enum_column.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,5 @@ Gem::Specification.new do |spec|
end
spec.require_paths = ["lib"]

spec.test_files = [
"test/test_helper.rb",
"test/db/schema.rb",
"test/fixtures/enumeration.rb",
"test/fixtures/enum_controller.rb",
"test/enum_controller_test.rb",
"test/enum_mysql_test.rb"
]
spec.add_dependency 'activerecord', '>= 4.2', '< 6'
end
2 changes: 2 additions & 0 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# frozen_string_literal: true

require File.dirname(__FILE__) + "/rails/init.rb"
2 changes: 2 additions & 0 deletions lib/active_record/mysql/enum.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

if defined?(::Rails::Railtie)
module ActiveRecord
module Mysql
Expand Down
2 changes: 2 additions & 0 deletions lib/active_record/mysql/enum/active_record_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

if defined?(Rails::Generator)
module Rails
module Generator
Expand Down
2 changes: 2 additions & 0 deletions lib/active_record/mysql/enum/enum_adapter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This module provides all the column helper methods to deal with the
# values and adds the common type management code for the adapters.

Expand Down
2 changes: 2 additions & 0 deletions lib/active_record/mysql/enum/enum_column_adapter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This module provides all the column helper methods to deal with the
# values and adds the common type management code for the adapters.

Expand Down
2 changes: 2 additions & 0 deletions lib/active_record/mysql/enum/enum_type.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

if defined? ActiveRecord::Type::Value
module ActiveRecord
module Type
Expand Down
34 changes: 26 additions & 8 deletions lib/active_record/mysql/enum/mysql_adapter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

adapter_class = if defined? ActiveRecord::ConnectionAdapters::MySQLJdbcConnection
ActiveRecord::ConnectionAdapters::MySQLJdbcConnection
# elsif defined? ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter
Expand Down Expand Up @@ -25,19 +27,35 @@ def native_database_types #:nodoc
# be done on a per adapter basis, but is generalized here.
#
# will generate enum('a', 'b', 'c') for :limit => [:a, :b, :c]
def type_to_sql(type, limit: nil, precision: nil, scale: nil, unsigned: nil, **) # :nodoc:
if type.to_s == 'enum'
native = native_database_types[type]
column_type_sql = (native || {})[:name] || 'enum'
if Rails::VERSION::MAJOR < 5
def type_to_sql(type, limit = nil, precision = nil, scale = nil, unsigned = nil, **_options) # :nodoc:
if type.to_s == 'enum'
native = native_database_types[type]
column_type_sql = (native || {})[:name] || 'enum'

column_type_sql << "(#{limit.map { |v| quote(v) }.join(',')})"
column_type_sql << "(#{limit.map { |v| quote(v) }.join(',')})"

column_type_sql
else
super(type, limit: limit, precision: precision, scale: scale, unsigned: unsigned)
column_type_sql
else
super(type, limit, precision, scale, unsigned)
end
end
else
def type_to_sql(type, limit: nil, precision: nil, scale: nil, unsigned: nil, **_options) # :nodoc:
if type.to_s == 'enum'
native = native_database_types[type]
column_type_sql = (native || {})[:name] || 'enum'

column_type_sql << "(#{limit.map { |v| quote(v) }.join(',')})"

column_type_sql
else
super(type, limit: limit, precision: precision, scale: scale, unsigned: unsigned)
end
end
end


private
def initialize_type_map(m = type_map)
super
Expand Down
22 changes: 17 additions & 5 deletions lib/active_record/mysql/enum/quoting.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
# frozen_string_literal: true

module ActiveRecord
module ConnectionAdapters # :nodoc:
module Quoting
alias __quote_enum quote

# Quote a symbol as a normal string. This will support quoting of
# enumerated values.
def quote(value)
if !value.is_a? Symbol
__quote_enum(value)
else
ActiveRecord::Base.send(:quote_bound_value, value.to_s)
if Rails::VERSION::MAJOR < 5
def quote(value, column = nil)
if !value.is_a? Symbol
__quote_enum(value, column)
else
ActiveRecord::Base.send(:quote_bound_value, value.to_s)
end
end
else
def quote(value)
if !value.is_a? Symbol
__quote_enum(value)
else
ActiveRecord::Base.send(:quote_bound_value, value.to_s)
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/active_record/mysql/enum/schema_definitions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true

module ActiveRecord
module ConnectionAdapters
Expand Down
1 change: 1 addition & 0 deletions lib/active_record/mysql/enum/validations.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true

module ActiveRecord
module Validations
Expand Down
2 changes: 1 addition & 1 deletion lib/active_record/mysql/enum/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module ActiveRecord
module Mysql
module Enum
VERSION = "0.1.0"
VERSION = "0.1.0.pre.1"
end
end
end
2 changes: 2 additions & 0 deletions rails/init.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# frozen_string_literal: true

require 'active_record/mysql/enum'
1 change: 1 addition & 0 deletions test/db/schema.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true

ActiveRecord::Schema.define do
create_table :enumerations, :force => true do |t|
Expand Down
2 changes: 2 additions & 0 deletions test/enum_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require File.dirname(__FILE__) + '/test_helper'
require 'fixtures/enumeration'
require 'fixtures/enum_controller'
Expand Down
2 changes: 2 additions & 0 deletions test/enum_mysql_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require File.dirname(__FILE__) + '/test_helper'
require 'fixtures/enumeration'

Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/enum_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class EnumController < ActionController::Base
layout false

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/enumeration.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true

class Enumeration < ActiveRecord::Base
validates_columns :color, :severity, :string_field, :int_field
Expand Down
Loading