progne_tapera 0.5 → 0.5.1
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 +4 -1
- data/Gemfile.lock +3 -3
- data/README.md +32 -23
- data/ROADMAP.md +6 -0
- data/lib/progne_tapera/enum_code.rb +8 -0
- data/lib/progne_tapera/enum_config.rb +11 -1
- data/lib/progne_tapera/enum_item.rb +4 -0
- data/lib/progne_tapera/enum_list.rb +7 -4
- 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: 1b75c6db277e6d4dc91e00f4ec698c406dfedecf
|
4
|
+
data.tar.gz: cea58d461a2471da8240fb568c70d26e07cb5360
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ed8152f257cba6d28b8160e38161f332dc5a561d2ec67963c2263480624008d9d5a9c3e096e0e05e4342834034c6e527fa289c2d8fe58cf3ff34b9ea33af07a
|
7
|
+
data.tar.gz: 125805f2dd69b3f4867be5500ccd73535eec0a05b17e1df5bd3fe80048c3a4a3d6eab645808eb9179e68f0ea8aa6ce36d219ed85576082109801eeac4a67fe2f
|
data/CHANGELOG.md
CHANGED
@@ -19,4 +19,7 @@
|
|
19
19
|
1. Improved the Enum List concern to add the .``lookup`` method
|
20
20
|
|
21
21
|
## v0.5
|
22
|
-
1.
|
22
|
+
1. Improved the Enum Config concern to be able to be extended by lambda
|
23
|
+
|
24
|
+
## v0.5.1
|
25
|
+
1. Improve the Enum config concern for the Item Methods module
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
progne_tapera (0.
|
4
|
+
progne_tapera (0.5)
|
5
5
|
rails (>= 4.2)
|
6
6
|
|
7
7
|
GEM
|
@@ -61,7 +61,7 @@ GEM
|
|
61
61
|
mime-types-data (~> 3.2015)
|
62
62
|
mime-types-data (3.2016.0521)
|
63
63
|
mini_portile2 (2.1.0)
|
64
|
-
minitest (5.
|
64
|
+
minitest (5.10.1)
|
65
65
|
nio4r (1.2.1)
|
66
66
|
nokogiri (1.6.8.1)
|
67
67
|
mini_portile2 (~> 2.1.0)
|
@@ -112,7 +112,7 @@ GEM
|
|
112
112
|
actionpack (>= 4.0)
|
113
113
|
activesupport (>= 4.0)
|
114
114
|
sprockets (>= 3.0.0)
|
115
|
-
thor (0.19.
|
115
|
+
thor (0.19.4)
|
116
116
|
thread_safe (0.3.5)
|
117
117
|
tzinfo (1.2.2)
|
118
118
|
thread_safe (~> 0.1)
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Progne Tapera
|
2
2
|
|
3
|
+
[](http://www.rubydoc.info/gems/progne_tapera/frames)
|
3
4
|
[](http://opensource.org/licenses/MIT)
|
5
|
+
|
4
6
|
[](https://badge.fury.io/rb/progne_tapera)
|
5
7
|
[](https://gemnasium.com/github.com/topbitdu/progne_tapera)
|
6
8
|
|
@@ -97,21 +99,28 @@ app/types/ethnicity.rb
|
|
97
99
|
```ruby
|
98
100
|
class Ethnicity < ActiveRecord::Type::Value
|
99
101
|
|
100
|
-
|
102
|
+
# The Item Methods module must be defined before the ``enum :china_ethnicity`` code block, so it could be called there.
|
103
|
+
module ItemMethods
|
101
104
|
|
102
|
-
|
103
|
-
# 用 :china_ethnicity 指定的 i18n 资源。
|
105
|
+
extend ActiveSupport::Concern
|
104
106
|
|
105
|
-
|
107
|
+
included do |includer|
|
108
|
+
|
109
|
+
def major?
|
110
|
+
'HA'==code
|
111
|
+
end
|
112
|
+
# Ethnicity::HAN.major? returns true
|
113
|
+
# Ethnicity::MONGEL.major? returns false
|
106
114
|
|
107
|
-
def major?
|
108
|
-
'HA'==code
|
109
115
|
end
|
110
|
-
# Ethnicity::HAN.major? returns true
|
111
|
-
# Ethnicity::MONGEL.major? returns false
|
112
116
|
|
113
117
|
end
|
114
118
|
|
119
|
+
include ProgneTapera::EnumConfig
|
120
|
+
|
121
|
+
enum :china_ethnicity
|
122
|
+
# 用 :china_ethnicity 指定的 i18n 资源。
|
123
|
+
|
115
124
|
end
|
116
125
|
```
|
117
126
|
|
@@ -169,19 +178,19 @@ include ProgneTapera::EnumCode
|
|
169
178
|
|
170
179
|
### Enum List concern
|
171
180
|
|
172
|
-
The Enum List concern do the following tasks for the includer automatically:
|
173
|
-
1. Include the Enumerable module
|
174
|
-
2. Define the .enum_name method as: ``enum_name(name = nil)``
|
175
|
-
3. Define the .item_defined? method as: ``item_defined?(item)``
|
176
|
-
4. Define the .add_item method as: ``add_item(item)``
|
177
|
-
5. Define the .safe_add_item method as: ``safe_add_item(item)``
|
178
|
-
6. Define the .enum_constants method as: ``enum_constants``
|
179
|
-
7. Define the .all method as: ``all``
|
180
|
-
8. Define the .selected method as: ``selected(&block)``
|
181
|
-
9. Define the .each method as: ``each(&block)``
|
181
|
+
The Enum List concern do the following tasks for the includer automatically:
|
182
|
+
1. Include the Enumerable module
|
183
|
+
2. Define the .enum_name method as: ``enum_name(name = nil)``
|
184
|
+
3. Define the .item_defined? method as: ``item_defined?(item)``
|
185
|
+
4. Define the .add_item method as: ``add_item(item)``
|
186
|
+
5. Define the .safe_add_item method as: ``safe_add_item(item)``
|
187
|
+
6. Define the .enum_constants method as: ``enum_constants``
|
188
|
+
7. Define the .all method as: ``all``
|
189
|
+
8. Define the .selected method as: ``selected(&block)``
|
190
|
+
9. Define the .each method as: ``each(&block)``
|
182
191
|
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)``
|
192
|
+
11. Define the .form_options method as: ``form_options(&block)``
|
193
|
+
12. Define the .deserialize method as: ``deserialize(value)``
|
185
194
|
13. Define the .serialize method as: ``serialize(value)``
|
186
195
|
|
187
196
|
```ruby
|
@@ -194,8 +203,8 @@ Gender.form_options # { '男' => '1', '女' => '2', '未指定' => '9' }
|
|
194
203
|
|
195
204
|
### Enum Config concern
|
196
205
|
|
197
|
-
The Enum Config concern do the following tasks for the includer automatically:
|
198
|
-
1. Include the Enum List concern
|
206
|
+
The Enum Config concern do the following tasks for the includer automatically:
|
207
|
+
1. Include the Enum List concern
|
199
208
|
2. Define the .enum method as: ``enum(name = nil, localized_name = name, &block)``
|
200
209
|
3. Define the .overload_enum_i18n method as: ``overload_enum_i18n(localized_name = nil)``
|
201
210
|
|
@@ -239,7 +248,7 @@ Ethnicity::YI.localized_name # '彝'
|
|
239
248
|
|
240
249
|
### Enum Code concern
|
241
250
|
|
242
|
-
The Enum Code concern do the following tasks for the includer automatically:
|
251
|
+
The Enum Code concern do the following tasks for the includer automatically:
|
243
252
|
1. Define the .code method as: ``code(field, enum)``
|
244
253
|
|
245
254
|
|
data/ROADMAP.md
CHANGED
@@ -20,3 +20,9 @@
|
|
20
20
|
|
21
21
|
## v0.5
|
22
22
|
1. Improve the Enum Code concern to be able to be extended by lambda
|
23
|
+
|
24
|
+
## v0.5.1
|
25
|
+
1. Improve the Enum config concern for the Item Methods module
|
26
|
+
|
27
|
+
## v0.6
|
28
|
+
1. Improve the Enum Config concern to make the enum items be able to be updated or destroyable through the #enum method
|
@@ -1,3 +1,6 @@
|
|
1
|
+
##
|
2
|
+
# Enum Code 是在模型层配置知识层枚举的关注点,提供 .code 宏方法。
|
3
|
+
|
1
4
|
module ProgneTapera::EnumCode
|
2
5
|
|
3
6
|
extend ActiveSupport::Concern
|
@@ -7,6 +10,11 @@ module ProgneTapera::EnumCode
|
|
7
10
|
|
8
11
|
module ClassMethods
|
9
12
|
|
13
|
+
##
|
14
|
+
# 为关注的类提供以下逻辑:
|
15
|
+
# 1. 验证 ``field``_code 字段的值,是否在枚举类型的定义中。
|
16
|
+
# 2. 定义 ``field`` 方法,用于获取枚举型的值。
|
17
|
+
# 3. 定义 ``field``= 方法,用于为枚举型字段赋值。
|
10
18
|
def code(field, enum)
|
11
19
|
code_field_name = :"#{field}_code"
|
12
20
|
validates code_field_name, inclusion: enum.all.map { |item| item.code }
|
@@ -1,3 +1,6 @@
|
|
1
|
+
##
|
2
|
+
# Enum Config 是知识层枚举类型的配置关注点。提供 .enum 和 .overload_enum_i18n 方法。
|
3
|
+
|
1
4
|
module ProgneTapera::EnumConfig
|
2
5
|
|
3
6
|
extend ActiveSupport::Concern
|
@@ -14,6 +17,7 @@ module ProgneTapera::EnumConfig
|
|
14
17
|
|
15
18
|
yield.each do |key, value|
|
16
19
|
options = value.map { |k, v| [ k.to_sym, v ] }.to_h
|
20
|
+
#options[:optional] = true if options[:optional].nil?
|
17
21
|
code = options.delete :code
|
18
22
|
safe_add_item ProgneTapera::EnumItem.new(code, key.to_s, options)
|
19
23
|
end
|
@@ -26,9 +30,15 @@ module ProgneTapera::EnumConfig
|
|
26
30
|
|
27
31
|
enumerations.each do |key, value|
|
28
32
|
options = value.map { |k, v| [ k.to_sym, v ] }.to_h
|
33
|
+
#options[:optional] = false
|
29
34
|
code = options.delete :code
|
30
35
|
options[:localized_name] = I18n.t "enum.#{localized_name||name}.#{key}"
|
31
|
-
|
36
|
+
item = ProgneTapera::EnumItem.new code, key, options
|
37
|
+
class << item
|
38
|
+
item_method_module = "#{self.name}::ItemMethods".safe_constantize
|
39
|
+
include item_method_module if item_method_module.present?
|
40
|
+
end
|
41
|
+
safe_add_item item
|
32
42
|
end
|
33
43
|
|
34
44
|
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
##
|
2
|
+
# Enum List 是知识层枚举列表的领域逻辑关注点。
|
2
3
|
|
3
4
|
module ProgneTapera::EnumList
|
4
5
|
|
@@ -26,9 +27,6 @@ module ProgneTapera::EnumList
|
|
26
27
|
raise ArgumentError.new "The #{item.inspect} item should be an instance of ProgneTapera::EnumItem." unless item.is_a? ProgneTapera::EnumItem
|
27
28
|
raise ArgumentError.new "The #{item.constant_name} enum item was defined already." if item_defined? item
|
28
29
|
|
29
|
-
item_methods_module = "#{self.name}::ItemMethods".safe_constantize
|
30
|
-
item.class.include item_methods_module if item_methods_module.present?
|
31
|
-
|
32
30
|
const_set item.constant_name, item
|
33
31
|
end
|
34
32
|
|
@@ -36,6 +34,11 @@ module ProgneTapera::EnumList
|
|
36
34
|
const_set item.constant_name, item if item.is_a?(ProgneTapera::EnumItem)&&!item_defined?(item)
|
37
35
|
end
|
38
36
|
|
37
|
+
# Destroy or Update the Enum Items
|
38
|
+
#def clear_optional_items
|
39
|
+
#
|
40
|
+
#end
|
41
|
+
|
39
42
|
# Infrastructure for the Enumerable
|
40
43
|
def enum_constants
|
41
44
|
constants.select { |constant|
|
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:
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Topbit Du
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|