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 +4 -4
- data/CHANGELOG.md +6 -3
- data/Gemfile.lock +1 -1
- data/README.md +40 -4
- data/ROADMAP.md +4 -1
- data/lib/progne_tapera/enum_list.rb +5 -0
- 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: 0f5f7b1c2bd253288fb395a9689477afd48296fc
|
4
|
+
data.tar.gz: 8b8222d20691909a97a1c0dcb62d85d7a3233964
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
13
|
+
1. Improved the Enum Config concern to support the customized enum i18n name
|
14
14
|
|
15
15
|
## v0.3
|
16
|
-
1.
|
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
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 .
|
156
|
-
11. Define the .
|
157
|
-
12. Define the .
|
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 :
|
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
|
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
|
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.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-
|
11
|
+
date: 2016-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|