progne_tapera 0.2 → 0.3

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: 10afe562fb832aeb33de65ed73dd5e18bf465c85
4
- data.tar.gz: 8a5d1f77fcf1f97304121df8b6f83548b06d4079
3
+ metadata.gz: c572ea05d76868e7f16a643e20a9a3c6eb36820d
4
+ data.tar.gz: 01d125c24cb51e1d29545b4e78fff1f61d37b384
5
5
  SHA512:
6
- metadata.gz: 31f8cb8c615dcb0862e0fc2dad0feff04f24956e5c0335366ded17f8cf4538eb12c08b03ddba604ba32298923c33ac064549e655e8eed0e5673a88421b7295c5
7
- data.tar.gz: 063a7070511318424744873786868fed98145644888faef68a9a3cc9575780ff027ce308ec06d6bca00fa4bcccaa3ce8395e340a1d90d8996bdd1f6845ecefa8
6
+ metadata.gz: 79a1a9ac26aad3ab40885b50a5589c4dcdb64a6d97e0bae01d934a36a74d8f526aa4762d057c2ad2231c0d0503e60d343633af2a6fd3b27f98e4d433da407d54
7
+ data.tar.gz: 6d0de604532c59caf306a4d715113a0a4989757c395d52fbe92577e6f9efbdbb52f70ccdc4ca1d72ff1c29ea521f9bada4a6fdb1b979dc77673d9934e9d0955f
data/CHANGELOG.md CHANGED
@@ -11,3 +11,6 @@
11
11
 
12
12
  ## v0.2
13
13
  1. Improve the Enum Config concern to support the customized enum i18n name
14
+
15
+ ## v0.3
16
+ 1. Improve the Enum Config concern to support the overloaded enum i18n name
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- progne_tapera (0.1.1)
4
+ progne_tapera (0.2)
5
5
  rails (>= 4.2)
6
6
 
7
7
  GEM
@@ -63,10 +63,8 @@ GEM
63
63
  mini_portile2 (2.1.0)
64
64
  minitest (5.9.1)
65
65
  nio4r (1.2.1)
66
- nokogiri (1.6.8)
66
+ nokogiri (1.6.8.1)
67
67
  mini_portile2 (~> 2.1.0)
68
- pkg-config (~> 1.1.7)
69
- pkg-config (1.1.7)
70
68
  rack (2.0.1)
71
69
  rack-test (0.6.3)
72
70
  rack (>= 1.0)
data/README.md CHANGED
@@ -124,6 +124,12 @@ class Ethnicity < ActiveRecord::Type::Value
124
124
  end
125
125
  ```
126
126
 
127
+ 在某处需要调用民族 (Ethnicity) 枚举型的代码中:
128
+ ```ruby
129
+ Ethnicity::HAN.code # 'HA'
130
+ Ethnicity::HAN.localized_name # '汉'
131
+ ```
132
+
127
133
 
128
134
 
129
135
  ## Include the Concerns
@@ -155,6 +161,32 @@ The Enum List concern do the following tasks for the includer automatically:
155
161
  The Enum Config concern do the following tasks for the includer automatically:
156
162
  1. Include the Enum List concern
157
163
  2. Define the .enum method as: ``enum(name = nil)``
164
+ 3. Define the .overload_enum_i18n method as: ``overload_enum_i18n(localized_name = nil)``
165
+
166
+ config/locales/enum.zh-CN.yml
167
+ ```yaml
168
+ 'zh-CN':
169
+ enum:
170
+
171
+ china_ethnicity_overloaded:
172
+ han: 汉族
173
+ mongel: 蒙古族
174
+ ```
175
+
176
+ ```ruby
177
+ # Overload the i18n resources of the Ethnicity enum code
178
+ Ethnicity.class_eval do
179
+ overload_enum_i18n :ethnicity_overloaded
180
+ end
181
+ ```
182
+
183
+ 在某处需要调用民族 (Ethnicity) 枚举型的代码中:
184
+ ```ruby
185
+ Ethnicity::HAN.code # 'HA'
186
+ Ethnicity::HAN.localized_name # '汉族' not '汉'
187
+ ```
188
+
189
+
158
190
 
159
191
  ### Enum Code concern
160
192
 
data/ROADMAP.md CHANGED
@@ -11,3 +11,6 @@
11
11
 
12
12
  ## v0.2
13
13
  1. Improve the Enum Config concern to support the customized enum i18n name
14
+
15
+ ## v0.3
16
+ 1. Improve the Enum Config concern to support the overloaded enum i18n name
@@ -9,15 +9,26 @@ module ProgneTapera::EnumConfig
9
9
  module ClassMethods
10
10
 
11
11
  def enum(name = nil, localized_name = name)
12
- name = enum_name(name).to_s
12
+
13
+ name = enum_name(name).to_s
13
14
  enumerations = Rails.configuration.enum[name]
14
- raise ArgumentError.new "The enum.#{name} was not configured in the config/enum.yml file." if enumerations.blank?
15
+ raise ArgumentError.new("The enum.#{name} was not configured in the config/enum.yml file.") if enumerations.blank?
16
+
15
17
  enumerations.each do |key, value|
16
18
  options = value.map { |k, v| [ k.to_sym, v ] }.to_h
17
19
  code = options.delete :code
18
- options[:localized_name] = I18n.t "enum.#{localized_name}.#{key}"
20
+ options[:localized_name] = I18n.t "enum.#{localized_name||name}.#{key}"
19
21
  safe_add_item ProgneTapera::EnumItem.new(code, key, options)
20
22
  end
23
+
24
+ end
25
+
26
+ def overload_enum_i18n(localized_name = nil)
27
+
28
+ each do |enum_item|
29
+ enum_item.options[:localized_name] = I18n.t "enum.#{localized_name}.#{enum_item.name}"
30
+ end
31
+
21
32
  end
22
33
 
23
34
  end
@@ -2,7 +2,7 @@ require 'rails'
2
2
 
3
3
  class ProgneTapera::EnumItem
4
4
 
5
- attr_reader :code, :name
5
+ attr_reader :code, :name, :options
6
6
 
7
7
  # code = HA (value)
8
8
  # name = han
@@ -10,8 +10,8 @@ class ProgneTapera::EnumItem
10
10
  # -> constant: HAN
11
11
  def initialize(code, name, options = {})
12
12
 
13
- raise ArgumentError.new 'The code argument is required.' if code.blank?
14
- raise ArgumentError.new 'The name argument is required.' if name.blank?
13
+ raise ArgumentError.new('The code argument is required.') if code.blank?
14
+ raise ArgumentError.new('The name argument is required.') if name.blank?
15
15
 
16
16
  @code = code
17
17
  @name = name
@@ -20,7 +20,7 @@ class ProgneTapera::EnumItem
20
20
  @options.each do |key, value|
21
21
  class_eval do
22
22
  define_method(key.to_sym) do
23
- value
23
+ @options[key] #value
24
24
  end
25
25
  end
26
26
  end
@@ -1,3 +1,3 @@
1
1
  module ProgneTapera
2
- VERSION = "0.2"
2
+ VERSION = '0.3'
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.2'
4
+ version: '0.3'
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-17 00:00:00.000000000 Z
11
+ date: 2016-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails