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 20302030 - Hour of Code
20312031 - 電子工作
20322032- id : 195
2033- order : 192074
2033+ order : ' 192074'
20342034 is_active : false
20352035 created_at : ' 2019-02-03'
20362036 name : 韮崎
20452045 - Python
20462046 - Processing
20472047- id : 196
2048- order : 192091
2048+ order : ' 192091'
20492049 is_active : false
20502050 created_at : ' 2019-02-03'
20512051 name : 北杜
22332233 - LEGO
22342234 - micro:bit
22352235- id : 197
2236- order : 212041
2236+ order : ' 212041'
22372237 is_active : false
22382238 created_at : ' 2019-02-03'
22392239 name : 東濃
Original file line number Diff line number Diff line change @@ -27,7 +27,12 @@ namespace :dojos do
2727 task update_db_by_yaml : :environment do
2828 dojos = Dojo . load_attributes_from_yaml
2929
30+ # DB 反映する前に YAML データをチェックする
31+ # https://railsguides.jp/error_reporting.html
32+
3033 dojos . each do |dojo |
34+ raise_if_invalid_dojo ( dojo )
35+
3136 d = Dojo . find_or_initialize_by ( id : dojo [ 'id' ] )
3237 d . name = dojo [ 'name' ]
3338 d . counter = dojo [ 'counter' ] || 1
@@ -50,6 +55,21 @@ namespace :dojos do
5055
5156 Rake ::Task [ 'dojos:update_db_by_yaml' ] . enhance ( [ 'postgresql:reset_pk_sequence' ] )
5257
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+
5373 # search order number for google spred sheets
5474 # 'yamlファイルのnameからorderの値を生成します'
5575 def search_order_number_by ( pre_city )
You can’t perform that action at this time.
0 commit comments