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/
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# CHANGELOG for `activerecord-mysql-enum`

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`

[0.1.0]: https://github.com/Invoca/activerecord-mysql-enum/tree/0.1.0
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
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# ActiveRecord::Mysql::Enum

This gem is an extension to ActiveRecord which enables native support of
enumerations in the database schema using the ENUM type in MySQL. Forked
and revitalized from [enum_column3](https://github.com/jewlr/enum_column)
which was itself a fork of a fork of Nick Pohodnya's original gem for
Rails 3, [enum_column3](https://github.com/electronick/enum_column).

## Support
Currently this has been manually tested with Rails version 4 and 5, and works with scaffolding.

**Supported adapters:**
- mysql
- mysql2
- jdbcmysql (by Nilesh Trivedi)

## Installation
In your `Gemfile` add the following snippet
```ruby
gem 'activerecord-mysql-enum', '~> 0.1', require: 'active_support/mysql/enum'
```

## Usage
### Schema Definitions
When defining an enum in your schema, specify the constraint as a limit:
```ruby
create_table :enumerations, :force => true do |t|
t.column :severity, :enum, :limit => [:low, :medium, :high, :critical], :default => :medium
t.column :color, :enum, :limit => [:red, :blue, :green, :yellow]
end
```

### Model Validations
You can then automatically validate this column using:
```ruby
validates_columns :severity, :color
```

### Setting/Getting Values
All enumerated values will be given as symbols.
```ruby
@e = Enumeration.new
@e.severity = :medium
```

You can always use the column reflection to get the list of possible values from the database column.
```ruby
irb(1)> Enumeration.columns_hash['color'].limit
=> [:red, :blue, :green, :yellow]
irb(2)> @enumeration.column_for_attribute(:color).limit
=> [:red, :blue, :green, :yellow]
```

### Form Helpers
You can use enum_select helper to generate input for enumerated attribute as:
```ruby
<%= enum_select(@enumeration, 'severity')%>
```

Or using `form_for`:
```ruby
<%= form_for @enumeration do |f| %>
<%= f.label :severity %>
<%= f.enum_select :severity %>
<% end %>
```
60 changes: 0 additions & 60 deletions README.txt

This file was deleted.

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
43 changes: 29 additions & 14 deletions enum_column.gemspec
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
# -*- encoding: utf-8 -*-
# stub: enum_column3 0.1.4 ruby lib
# frozen_string_literal: true

Gem::Specification.new do |s|
s.name = "enum_column3"
s.version = "5.1.1"
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "active_record/mysql/enum/version"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib"]
s.authors = ["Nick Pohodnya"]
s.date = "2015-08-19"
s.files = ["LICENSE", "README.txt", "init.rb", "lib/enum/active_record_helper.rb", "lib/enum/enum_adapter.rb", "lib/enum/mysql_adapter.rb", "lib/enum/quoting.rb", "lib/enum/schema_definitions.rb", "lib/enum/schema_statements.rb", "lib/enum/validations.rb", "lib/enum_column.rb", "lib/enum_column3.rb", "test/db/schema.rb", "test/enum_controller_test.rb", "test/enum_mysql_test.rb", "test/fixtures/enum_controller.rb", "test/fixtures/enumeration.rb", "test/test_helper.rb"]
s.homepage = "http://github.com/electronick/enum_column"
s.rubygems_version = "2.4.8"
s.summary = "Enable enum type for MySQL db."
s.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"]
Gem::Specification.new do |spec|
spec.name = "activerecord-mysql-enum"
spec.version = ActiveRecord::Mysql::Enum::VERSION
spec.authors = ["Nick Pohodnya", "Invoca Development"]
spec.email = ["development@invoca.com"]

spec.summary = "Enable enum type for the MySQL Adapter in ActiveRecord"
spec.description = spec.summary
spec.homepage = "http://github.com/Invoca/activerecord-mysql-enum"

# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
spec.metadata = {
"source_code_uri" => "https://github.com/Invoca/activerecord-mysql-enum",
'allowed_push_host' => "https://rubygems.org"
}

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
spec.require_paths = ["lib"]

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"
Loading