progne_tapera 0.3 → 0.4

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: c572ea05d76868e7f16a643e20a9a3c6eb36820d
4
- data.tar.gz: 01d125c24cb51e1d29545b4e78fff1f61d37b384
3
+ metadata.gz: 0f5f7b1c2bd253288fb395a9689477afd48296fc
4
+ data.tar.gz: 8b8222d20691909a97a1c0dcb62d85d7a3233964
5
5
  SHA512:
6
- metadata.gz: 79a1a9ac26aad3ab40885b50a5589c4dcdb64a6d97e0bae01d934a36a74d8f526aa4762d057c2ad2231c0d0503e60d343633af2a6fd3b27f98e4d433da407d54
7
- data.tar.gz: 6d0de604532c59caf306a4d715113a0a4989757c395d52fbe92577e6f9efbdbb52f70ccdc4ca1d72ff1c29ea521f9bada4a6fdb1b979dc77673d9934e9d0955f
6
+ metadata.gz: 1663219296095eb5c07acc5c7118e7517057b7a086adcd6826c19a20fe8fa0a8f605afdaaf06d2086f5c87c67bf71e0794a78f92539032a4ab9c9eea5593a1bc
7
+ data.tar.gz: 4e4c9d42fbe51f7deaa27c8cca6695d6c6dcdd2373aa6c7a477da860f5304db9e4c24c5a72c061a65c1544a5c7c62cc66402b588fc0cca92ae2336050101edb8
data/CHANGELOG.md CHANGED
@@ -7,10 +7,13 @@
7
7
  4. Enum Code concern
8
8
 
9
9
  ## v0.1.1
10
- 1. Improve the Ruby Gem Specification to depend on Rails v4.2
10
+ 1. Improved the Ruby Gem Specification to depend on [rails](https://github.com/rails/rails) v4.2
11
11
 
12
12
  ## v0.2
13
- 1. Improve the Enum Config concern to support the customized enum i18n name
13
+ 1. Improved the Enum Config concern to support the customized enum i18n name
14
14
 
15
15
  ## v0.3
16
- 1. Improve the Enum Config concern to support the overloaded enum i18n name
16
+ 1. Improved the Enum Config concern to support the overloaded enum i18n name
17
+
18
+ ## v0.4
19
+ 1. Improve the Enum List concern to add the .``lookup`` method
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- progne_tapera (0.2)
4
+ progne_tapera (0.3)
5
5
  rails (>= 4.2)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -37,11 +37,13 @@ Or install it yourself as:
37
37
  ## Usage
38
38
 
39
39
  config/initializers/enum.rb
40
+
40
41
  ```ruby
41
42
  Unidom::Common::YamlHelper.load_enum config: Rails.configuration, root: Rails.root
42
43
  ```
43
44
 
44
45
  config/enum.yml
46
+
45
47
  ```yaml
46
48
  enum:
47
49
 
@@ -63,6 +65,7 @@ enum:
63
65
  ```
64
66
 
65
67
  config/locales/enum.zh-CN.yml
68
+
66
69
  ```yaml
67
70
  'zh-CN':
68
71
  enum:
@@ -78,6 +81,7 @@ config/locales/enum.zh-CN.yml
78
81
  ```
79
82
 
80
83
  app/types/gender.rb
84
+
81
85
  ```ruby
82
86
  class Gender < ActiveRecord::Type::Value
83
87
 
@@ -89,6 +93,7 @@ end
89
93
  ```
90
94
 
91
95
  app/types/ethnicity.rb
96
+
92
97
  ```ruby
93
98
  class Ethnicity < ActiveRecord::Type::Value
94
99
 
@@ -97,10 +102,21 @@ class Ethnicity < ActiveRecord::Type::Value
97
102
  enum :china_ethnicity
98
103
  # 用 :china_ethnicity 指定的 i18n 资源。
99
104
 
105
+ module ItemMethods
106
+
107
+ def major?
108
+ 'HA'==code
109
+ end
110
+ # Ethnicity::HAN.major? returns true
111
+ # Ethnicity::MONGEL.major? returns false
112
+
113
+ end
114
+
100
115
  end
101
116
  ```
102
117
 
103
118
  app/types/ethnicity.rb
119
+
104
120
  ```ruby
105
121
  class Ethnicity < ActiveRecord::Type::Value
106
122
 
@@ -113,6 +129,7 @@ end
113
129
  ```
114
130
 
115
131
  app/types/ethnicity.rb
132
+
116
133
  ```ruby
117
134
  class Ethnicity < ActiveRecord::Type::Value
118
135
 
@@ -125,11 +142,21 @@ end
125
142
  ```
126
143
 
127
144
  在某处需要调用民族 (Ethnicity) 枚举型的代码中:
145
+
128
146
  ```ruby
129
147
  Ethnicity::HAN.code # 'HA'
130
148
  Ethnicity::HAN.localized_name # '汉'
131
149
  ```
132
150
 
151
+ 在使用枚举型的模型中:(如 app/models/person.rb)
152
+
153
+ ```ruby
154
+ class Person < ActiveRecord::Base
155
+ code :ethnicity, Ethnicity
156
+ # The :ethnicity above implies the Person model has the :ethnicity_code field.
157
+ end
158
+ ```
159
+
133
160
 
134
161
 
135
162
  ## Include the Concerns
@@ -152,9 +179,18 @@ The Enum List concern do the following tasks for the includer automatically:
152
179
  7. Define the .all method as: ``all``
153
180
  8. Define the .selected method as: ``selected(&block)``
154
181
  9. Define the .each method as: ``each(&block)``
155
- 10. Define the .form_options method as: ``form_options(&block)``
156
- 11. Define the .deserialize method as: ``deserialize(value)``
157
- 12. Define the .serialize method as: ``serialize(value)``
182
+ 10. Define the .lookup method as: ``lookup(code)``
183
+ 11. Define the .form_options method as: ``form_options(&block)``
184
+ 12. Define the .deserialize method as: ``deserialize(value)``
185
+ 13. Define the .serialize method as: ``serialize(value)``
186
+
187
+ ```ruby
188
+ gender = Gender.lookup '1' # Lookup the gender per code
189
+ gender.name # male
190
+
191
+ Gender.form_options # { '男' => '1', '女' => '2', '未指定' => '9' }
192
+ # It's useful for the HTML select options
193
+ ```
158
194
 
159
195
  ### Enum Config concern
160
196
 
@@ -176,7 +212,7 @@ config/locales/enum.zh-CN.yml
176
212
  ```ruby
177
213
  # Overload the i18n resources of the Ethnicity enum code
178
214
  Ethnicity.class_eval do
179
- overload_enum_i18n :ethnicity_overloaded
215
+ overload_enum_i18n :china_ethnicity_overloaded
180
216
  end
181
217
  ```
182
218
 
data/ROADMAP.md CHANGED
@@ -7,10 +7,13 @@
7
7
  4. Enum Code concern
8
8
 
9
9
  ## v0.1.1
10
- 1. Improve the Ruby Gem Specification to depend on Rails v4.2
10
+ 1. Improve the Ruby Gem Specification to depend on [rails](https://github.com/rails/rails) v4.2
11
11
 
12
12
  ## v0.2
13
13
  1. Improve the Enum Config concern to support the customized enum i18n name
14
14
 
15
15
  ## v0.3
16
16
  1. Improve the Enum Config concern to support the overloaded enum i18n name
17
+
18
+ ## v0.4
19
+ 1. Improve the Enum List concern to add the .``lookup`` method
@@ -57,6 +57,11 @@ module ProgneTapera::EnumList
57
57
  all.each &block
58
58
  end
59
59
 
60
+ # Lookup
61
+ def lookup(code)
62
+ select { |item| item.code==code }.first
63
+ end
64
+
60
65
  # Form Option
61
66
  def form_options(&block)
62
67
  items = block_given? ? selected(&block) : selected
@@ -1,3 +1,3 @@
1
1
  module ProgneTapera
2
- VERSION = '0.3'
2
+ VERSION = '0.4'
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.3'
4
+ version: '0.4'
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-21 00:00:00.000000000 Z
11
+ date: 2016-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails