progne_tapera 0.4 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -1
- data/Gemfile.lock +1 -1
- data/README.md +14 -1
- data/ROADMAP.md +3 -0
- data/lib/progne_tapera/enum_config.rb +21 -9
- data/lib/progne_tapera/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c2a069aea2e81297eeac4d046451dbc3f94601c
|
4
|
+
data.tar.gz: b71391edfc0e159fbe3897b26181cf8db8042aa5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6304fa68a8688b52add3af79d93912a5d0db3af98f15c12a0f6dff3408f4b63d21dcbb787ca72b882c344f0030cf43c1bf2c3b44a817a5b9832905475c670506
|
7
|
+
data.tar.gz: f0b24325729107a134e6994ca57196f9f18d2e657938b44ad10f2b54be30dad1435b21423c91366dcd859f885b57625cec8ba4793a307987213e30e384a5cb0b
|
data/CHANGELOG.md
CHANGED
@@ -16,4 +16,7 @@
|
|
16
16
|
1. Improved the Enum Config concern to support the overloaded enum i18n name
|
17
17
|
|
18
18
|
## v0.4
|
19
|
-
1.
|
19
|
+
1. Improved the Enum List concern to add the .``lookup`` method
|
20
|
+
|
21
|
+
## v0.5
|
22
|
+
1. Improve the Enum Code concern to be able to be extended by lambda
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -196,7 +196,7 @@ Gender.form_options # { '男' => '1', '女' => '2', '未指定' => '9' }
|
|
196
196
|
|
197
197
|
The Enum Config concern do the following tasks for the includer automatically:
|
198
198
|
1. Include the Enum List concern
|
199
|
-
2. Define the .enum method as: ``enum(name = nil)``
|
199
|
+
2. Define the .enum method as: ``enum(name = nil, localized_name = name, &block)``
|
200
200
|
3. Define the .overload_enum_i18n method as: ``overload_enum_i18n(localized_name = nil)``
|
201
201
|
|
202
202
|
config/locales/enum.zh-CN.yml
|
@@ -222,7 +222,20 @@ Ethnicity::HAN.code # 'HA'
|
|
222
222
|
Ethnicity::HAN.localized_name # '汉族' not '汉'
|
223
223
|
```
|
224
224
|
|
225
|
+
基于数据或者其他的方式扩展枚举型:
|
226
|
+
```ruby
|
227
|
+
Ethnicity.enum do
|
228
|
+
{
|
229
|
+
miao: { code: 'MH', numeric_code: '06', localized_name: '苗' },
|
230
|
+
yi: { code: 'YI', numeric_code: '07', localized_name: '彝' }
|
231
|
+
}
|
232
|
+
end
|
225
233
|
|
234
|
+
Ethnicity::MIAO.code # 'MH'
|
235
|
+
Ethnicity::MIAO.localized_name # '苗'
|
236
|
+
Ethnicity::YI.code # 'YI'
|
237
|
+
Ethnicity::YI.localized_name # '彝'
|
238
|
+
```
|
226
239
|
|
227
240
|
### Enum Code concern
|
228
241
|
|
data/ROADMAP.md
CHANGED
@@ -10,15 +10,27 @@ module ProgneTapera::EnumConfig
|
|
10
10
|
|
11
11
|
def enum(name = nil, localized_name = name)
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
13
|
+
if block_given?
|
14
|
+
|
15
|
+
yield.each do |key, value|
|
16
|
+
options = value.map { |k, v| [ k.to_sym, v ] }.to_h
|
17
|
+
code = options.delete :code
|
18
|
+
safe_add_item ProgneTapera::EnumItem.new(code, key.to_s, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
else
|
22
|
+
|
23
|
+
name = enum_name(name).to_s
|
24
|
+
enumerations = Rails.configuration.enum[name]
|
25
|
+
raise ArgumentError.new("The enum.#{name} was not configured in the config/enum.yml file.") if enumerations.blank?
|
26
|
+
|
27
|
+
enumerations.each do |key, value|
|
28
|
+
options = value.map { |k, v| [ k.to_sym, v ] }.to_h
|
29
|
+
code = options.delete :code
|
30
|
+
options[:localized_name] = I18n.t "enum.#{localized_name||name}.#{key}"
|
31
|
+
safe_add_item ProgneTapera::EnumItem.new(code, key, options)
|
32
|
+
end
|
33
|
+
|
22
34
|
end
|
23
35
|
|
24
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: progne_tapera
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.5'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Topbit Du
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|