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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b1fb56c71d55485d1b9c413179c4ec402c4b3ea0b3e9ee362b213122f6fdc6c
4
- data.tar.gz: 2e105e8b000e82fc026ebf56aecbd1de97ac944b8f20294615af88efaf95c49c
3
+ metadata.gz: 31095c38410d72dc36b68e0eb2fe538a2bb09246fd2195e80d3441e05fb6a697
4
+ data.tar.gz: 2c62a01900ee464b3de4cca4ebc17de9e8e53a5b3f3e211acbf224f52cc80c49
5
5
  SHA512:
6
- metadata.gz: e4f0adcc0a7829ad4d44449eb930e76eed390ea39037f34fabcd640bff615a02ce0b63f6910264f532798381b58527eabf4392b64b77957bce28faf05f494a8a
7
- data.tar.gz: ca449b158ab5a0c9a487e95300d0ad91b8581afda1dd28373bd29fb03ceb6a1d94977c0cb0a0ab38fbff462ce34f9807fb22467833313396e493cfdb387df5e5
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.
@@ -2,19 +2,22 @@ module EnumHelp
2
2
 
3
3
  module I18n
4
4
 
5
- if ActiveRecord::VERSION::MAJOR == 7
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
- end
17
- if ActiveRecord::VERSION::MAJOR < 7
20
+ else
18
21
  # overwrite the enum method
19
22
  def enum( definitions )
20
23
  super( definitions )
@@ -1,3 +1,3 @@
1
1
  module EnumHelp
2
- VERSION = "0.0.18"
2
+ VERSION = "0.0.19"
3
3
  end
@@ -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
- else
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]
@@ -1,4 +1,4 @@
1
- zh-CN:
1
+ en:
2
2
  activerecord:
3
3
  models:
4
4
  user: "User"
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.18
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-01-08 00:00:00.000000000 Z
11
+ date: 2022-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport