progne_tapera 0.4 → 0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f5f7b1c2bd253288fb395a9689477afd48296fc
4
- data.tar.gz: 8b8222d20691909a97a1c0dcb62d85d7a3233964
3
+ metadata.gz: 2c2a069aea2e81297eeac4d046451dbc3f94601c
4
+ data.tar.gz: b71391edfc0e159fbe3897b26181cf8db8042aa5
5
5
  SHA512:
6
- metadata.gz: 1663219296095eb5c07acc5c7118e7517057b7a086adcd6826c19a20fe8fa0a8f605afdaaf06d2086f5c87c67bf71e0794a78f92539032a4ab9c9eea5593a1bc
7
- data.tar.gz: 4e4c9d42fbe51f7deaa27c8cca6695d6c6dcdd2373aa6c7a477da860f5304db9e4c24c5a72c061a65c1544a5c7c62cc66402b588fc0cca92ae2336050101edb8
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. Improve the Enum List concern to add the .``lookup`` method
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- progne_tapera (0.3)
4
+ progne_tapera (0.4)
5
5
  rails (>= 4.2)
6
6
 
7
7
  GEM
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
@@ -17,3 +17,6 @@
17
17
 
18
18
  ## v0.4
19
19
  1. Improve 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
@@ -10,15 +10,27 @@ module ProgneTapera::EnumConfig
10
10
 
11
11
  def enum(name = nil, localized_name = name)
12
12
 
13
- name = enum_name(name).to_s
14
- enumerations = Rails.configuration.enum[name]
15
- raise ArgumentError.new("The enum.#{name} was not configured in the config/enum.yml file.") if enumerations.blank?
16
-
17
- enumerations.each do |key, value|
18
- options = value.map { |k, v| [ k.to_sym, v ] }.to_h
19
- code = options.delete :code
20
- options[:localized_name] = I18n.t "enum.#{localized_name||name}.#{key}"
21
- safe_add_item ProgneTapera::EnumItem.new(code, key, options)
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
@@ -1,3 +1,3 @@
1
1
  module ProgneTapera
2
- VERSION = '0.4'
2
+ VERSION = '0.5'
3
3
  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'
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-29 00:00:00.000000000 Z
11
+ date: 2016-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails