enum_help 0.0.18 → 0.0.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/enum_help/i18n.rb +9 -6
- data/lib/enum_help/version.rb +1 -1
- data/spec/enum_i18n_help_spec.rb +3 -1
- data/spec/fixtures/locales/en.yml +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31095c38410d72dc36b68e0eb2fe538a2bb09246fd2195e80d3441e05fb6a697
|
4
|
+
data.tar.gz: 2c62a01900ee464b3de4cca4ebc17de9e8e53a5b3f3e211acbf224f52cc80c49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5626546f63adea2e0742ee1adf325f4ee9cf6d6673068d7b239d88f907a5b270e0c02e1b1207896bb5e635b9e4d892b204a6c4b18af14ec8c8bdda848fef136
|
7
|
+
data.tar.gz: ebaec0dbcb3423c2ce8c720f385df4091e713a6e06e1516985bba3bbf079f68921ee3dfd99520dde9f4e3d0e26039eb196becf7197d89eaf77016d7b0eeba894
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# EnumHelp
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/enum_help.svg)](https://rubygems.org/gems/enum_help)
|
4
|
+
[![Build Status](https://github.com/zmbacker/enum_help/actions/workflows/ci.yml/badge.svg)](https://github.com/zmbacker/enum_help/actions/workflows/ci.yml)
|
5
|
+
|
3
6
|
Help ActiveRecord::Enum feature to work fine with I18n and simple_form.
|
4
7
|
|
5
8
|
Make Enum field correctly generate select field.
|
data/lib/enum_help/i18n.rb
CHANGED
@@ -2,19 +2,22 @@ module EnumHelp
|
|
2
2
|
|
3
3
|
module I18n
|
4
4
|
|
5
|
-
if ActiveRecord::VERSION::MAJOR
|
5
|
+
if ActiveRecord::VERSION::MAJOR >= 7
|
6
6
|
# overwrite the enum method
|
7
7
|
def enum(name = nil, values = nil, **options)
|
8
8
|
super(name, values, **options)
|
9
|
-
|
10
|
-
definitions = options.slice!(:_prefix, :_suffix, :_scopes, :_default)
|
11
|
-
definitions.each do |name, _|
|
9
|
+
if name # For new syntax in Rails7
|
12
10
|
Helper.define_attr_i18n_method(self, name)
|
13
11
|
Helper.define_collection_i18n_method(self, name)
|
12
|
+
else
|
13
|
+
definitions = options.slice!(:_prefix, :_suffix, :_scopes, :_default)
|
14
|
+
definitions.each do |name, _|
|
15
|
+
Helper.define_attr_i18n_method(self, name)
|
16
|
+
Helper.define_collection_i18n_method(self, name)
|
17
|
+
end
|
14
18
|
end
|
15
19
|
end
|
16
|
-
|
17
|
-
if ActiveRecord::VERSION::MAJOR < 7
|
20
|
+
else
|
18
21
|
# overwrite the enum method
|
19
22
|
def enum( definitions )
|
20
23
|
super( definitions )
|
data/lib/enum_help/version.rb
CHANGED
data/spec/enum_i18n_help_spec.rb
CHANGED
@@ -5,8 +5,10 @@ EnumHelp::Railtie.initializers.each(&:run)
|
|
5
5
|
class User < ActiveRecord::Base
|
6
6
|
if ActiveRecord.version < Gem::Version.new('6.1')
|
7
7
|
enum gender: [:male, :female]
|
8
|
-
|
8
|
+
elsif ActiveRecord.version < Gem::Version.new('7.0')
|
9
9
|
enum gender: [:male, :female], _default: :male
|
10
|
+
else # Rails 7.0 or higher
|
11
|
+
enum :gender, [:male, :female], default: :male
|
10
12
|
end
|
11
13
|
|
12
14
|
enum status: %i[normal disable]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enum_help
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lester Zhao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|