enum_i18n_help 0.1.0 → 0.1.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.
- checksums.yaml +5 -5
- data/.travis.yml +10 -0
- data/README.md +55 -12
- data/lib/enum_i18n_help/enum_i18n.rb +10 -2
- data/lib/enum_i18n_help/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c49dd954210f837a832afee83804d1cb2e176042e854519d75f4730ce5f9d627
|
4
|
+
data.tar.gz: 6c1d788a23e159f929eec6e1ee3c55d90bf1cf85cda76a2e83fe5d0d100d961e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 486374faf6157452787409453fc92346924a5b5bde0e05d99fa008db3c7b350d257b31971eb1c4bfd957a6fb2b2d4343c82be038809a5c16e78c44e42b4692eb
|
7
|
+
data.tar.gz: d8ec3e6586a252c4bf02809c0d5397fd79a34a0112422b7c2488a0263e94ef7e38e440b2be83275119ebc50040ac355d35fbcd8b9f613011cbb9dd763ac36da4
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# EnumI18nHelp
|
2
2
|
|
3
|
-
|
3
|
+
Help ActiveRecord::Enum feature to work with I18n.
|
4
4
|
|
5
|
-
|
5
|
+
added a new Test::Unit to the existing EnumHelp gem and changed the namespace of I18n.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,22 +22,65 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
model
|
26
26
|
|
27
|
-
|
27
|
+
```ruby
|
28
|
+
class User < ActiveRecord::Base
|
29
|
+
enum role: { manager: 1, member: 2 }
|
30
|
+
end
|
31
|
+
```
|
28
32
|
|
29
|
-
|
33
|
+
I18n
|
30
34
|
|
31
|
-
|
35
|
+
```ruby
|
36
|
+
ja:
|
37
|
+
activerecord:
|
38
|
+
attributes:
|
39
|
+
user/role:
|
40
|
+
manager: 管理者
|
41
|
+
member: 一般
|
42
|
+
```
|
32
43
|
|
33
|
-
|
44
|
+
```ruby
|
45
|
+
en:
|
46
|
+
activerecord:
|
47
|
+
attributes:
|
48
|
+
user/role:
|
49
|
+
manager: Manager
|
50
|
+
member: Member
|
51
|
+
```
|
34
52
|
|
35
|
-
|
53
|
+
### enum_column_text
|
36
54
|
|
37
|
-
|
55
|
+
```ruby
|
56
|
+
user = User.first
|
57
|
+
user.role
|
58
|
+
=> "manager"
|
59
|
+
user.role_text
|
60
|
+
=> "管理者"
|
61
|
+
```
|
38
62
|
|
39
|
-
|
63
|
+
change locale
|
40
64
|
|
41
|
-
|
65
|
+
```ruby
|
66
|
+
I18n.locale = :en
|
67
|
+
user.role
|
68
|
+
=> "manager"
|
69
|
+
user.role_text
|
70
|
+
=> "Manager"
|
71
|
+
```
|
72
|
+
|
73
|
+
### enum_column_options
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
User.role_options
|
77
|
+
=> [["管理者", :manager], ["一般", :member]]
|
78
|
+
```
|
79
|
+
|
80
|
+
## Contributing
|
42
81
|
|
43
|
-
|
82
|
+
1. Fork it ( https://github.com/ShuheiTsuji/enum_i18n_help )
|
83
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
84
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
85
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
86
|
+
5. Create new Pull Request
|
@@ -2,9 +2,16 @@ module EnumI18nHelp
|
|
2
2
|
module EnumI18n
|
3
3
|
def enum(definitions)
|
4
4
|
super(definitions)
|
5
|
-
|
5
|
+
# super has defined enum.
|
6
|
+
# So defined_enums are available!
|
7
|
+
#
|
8
|
+
# To avoid defining methods multiple times,
|
9
|
+
# slices hash to get enums called this time.
|
10
|
+
#
|
11
|
+
# Be careful not to destroy defined_enum, such as using merge!
|
12
|
+
defined_enums.slice(*definitions.keys.map(&:to_s)).each_pair do |key, value|
|
6
13
|
EnumAttribute.define_text_method!(self, key)
|
7
|
-
EnumAttribute.define_options_method!(self, key, value)
|
14
|
+
EnumAttribute.define_options_method!(self, key, value.symbolize_keys)
|
8
15
|
end
|
9
16
|
end
|
10
17
|
end
|
@@ -20,6 +27,7 @@ module EnumI18nHelp
|
|
20
27
|
METHOD
|
21
28
|
end
|
22
29
|
|
30
|
+
# This method assume that attr_value is a symbolized hash
|
23
31
|
def define_options_method!(klass, attr_name, attr_value)
|
24
32
|
attr_value_hash = attr_value.keys.map { |key| [key, key.to_s.humanize] }.to_h
|
25
33
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enum_i18n_help
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ShuheiTsuji
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -131,6 +131,7 @@ extra_rdoc_files: []
|
|
131
131
|
files:
|
132
132
|
- ".gitignore"
|
133
133
|
- ".rspec"
|
134
|
+
- ".travis.yml"
|
134
135
|
- CODE_OF_CONDUCT.md
|
135
136
|
- Gemfile
|
136
137
|
- LICENSE.txt
|
@@ -161,8 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
162
|
- !ruby/object:Gem::Version
|
162
163
|
version: '0'
|
163
164
|
requirements: []
|
164
|
-
|
165
|
-
rubygems_version: 2.5.1
|
165
|
+
rubygems_version: 3.0.3
|
166
166
|
signing_key:
|
167
167
|
specification_version: 4
|
168
168
|
summary: Enum attributes with I18n and ActiveRecord support
|