File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 2030
2030
- Hour of Code
2031
2031
- 電子工作
2032
2032
- id : 195
2033
- order : 192074
2033
+ order : ' 192074'
2034
2034
is_active : false
2035
2035
created_at : ' 2019-02-03'
2036
2036
name : 韮崎
2045
2045
- Python
2046
2046
- Processing
2047
2047
- id : 196
2048
- order : 192091
2048
+ order : ' 192091'
2049
2049
is_active : false
2050
2050
created_at : ' 2019-02-03'
2051
2051
name : 北杜
2233
2233
- LEGO
2234
2234
- micro:bit
2235
2235
- id : 197
2236
- order : 212041
2236
+ order : ' 212041'
2237
2237
is_active : false
2238
2238
created_at : ' 2019-02-03'
2239
2239
name : 東濃
Original file line number Diff line number Diff line change @@ -27,7 +27,12 @@ namespace :dojos do
27
27
task update_db_by_yaml : :environment do
28
28
dojos = Dojo . load_attributes_from_yaml
29
29
30
+ # DB 反映する前に YAML データをチェックする
31
+ # https://railsguides.jp/error_reporting.html
32
+
30
33
dojos . each do |dojo |
34
+ raise_if_invalid_dojo ( dojo )
35
+
31
36
d = Dojo . find_or_initialize_by ( id : dojo [ 'id' ] )
32
37
d . name = dojo [ 'name' ]
33
38
d . counter = dojo [ 'counter' ] || 1
@@ -50,6 +55,21 @@ namespace :dojos do
50
55
51
56
Rake ::Task [ 'dojos:update_db_by_yaml' ] . enhance ( [ 'postgresql:reset_pk_sequence' ] )
52
57
58
+ # YAML にある各 Dojo データが有効かどうか検証し、無効なら raise する
59
+ def raise_if_invalid_dojo ( dojo )
60
+ # order は必ず6桁になる https://www.soumu.go.jp/denshijiti/code.html
61
+ invalid_order = <<~ERROR_MESSAGE
62
+ 全国地方公共団体コード (order) は必ず6桁のコード (String) になります。内容を再度ご確認ください。
63
+ https://www.soumu.go.jp/denshijiti/code.html
64
+
65
+ Invalid Dojo: #{ dojo }
66
+
67
+ ERROR_MESSAGE
68
+
69
+ raise invalid_order if not dojo [ 'order' ] . size . equal? 6
70
+ raise invalid_order if not dojo [ 'order' ] . is_a? String
71
+ end
72
+
53
73
# search order number for google spred sheets
54
74
# 'yamlファイルのnameからorderの値を生成します'
55
75
def search_order_number_by ( pre_city )
You can’t perform that action at this time.
0 commit comments