Commit 60f24814145eee3c2f876ef130cf5634b31e6dad
1 parent
15dcbd86
Exists in
gov_user_refactory
Reduce cyclomatic complexity on set_errors
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing
1 changed file
with
18 additions
and
10 deletions
Show diff stats
controllers/gov_user_plugin_controller.rb
| 1 | 1 | #aqui deve ter so usuario e instituicao |
| 2 | 2 | class GovUserPluginController < ApplicationController |
| 3 | + VERIFY_ERRORS_IN = [ | |
| 4 | + :name, :country, :state, :city, :corporate_name, :cnpj, | |
| 5 | + :governmental_sphere, :governmental_power, :juridical_nature, :sisp | |
| 6 | + ] | |
| 3 | 7 | |
| 4 | 8 | def hide_registration_incomplete_percentage |
| 5 | 9 | response = false |
| ... | ... | @@ -245,16 +249,20 @@ class GovUserPluginController < ApplicationController |
| 245 | 249 | institution.valid? if institution |
| 246 | 250 | institution.community.valid? if institution.community |
| 247 | 251 | |
| 248 | - flash[:error_community_name] = institution.community.errors.include?(:name) ? "highlight-error" : "" | |
| 249 | - flash[:error_community_country] = institution.errors.include?(:country) ? "highlight-error" : "" | |
| 250 | - flash[:error_community_state] = institution.errors.include?(:state) ? "highlight-error" : "" | |
| 251 | - flash[:error_community_city] = institution.errors.include?(:city) ? "highlight-error" : "" | |
| 252 | - flash[:error_institution_corporate_name] = institution.errors.include?(:corporate_name) ? "highlight-error" : "" | |
| 253 | - flash[:error_institution_cnpj] = institution.errors.include?(:cnpj) ? "highlight-error" : "" | |
| 254 | - flash[:error_institution_governmental_sphere] = institution.errors.include?(:governmental_sphere) ? "highlight-error" : "" | |
| 255 | - flash[:error_institution_governmental_power] = institution.errors.include?(:governmental_power) ? "highlight-error" : "" | |
| 256 | - flash[:error_institution_juridical_nature] = institution.errors.include?(:juridical_nature) ? "highlight-error" : "" | |
| 257 | - flash[:error_institution_sisp] = institution.errors.include?(:sisp) ? "highlight-error" : "" | |
| 252 | + dispatch_flash_errors institution, "institution" | |
| 253 | + dispatch_flash_errors institution.community, "community" | |
| 254 | + end | |
| 255 | + | |
| 256 | + def dispatch_flash_errors model, flash_key_base | |
| 257 | + model.errors.messages.keys.each do |error_key| | |
| 258 | + flash_key = "error_#{flash_key_base}_#{error_key}".to_sym | |
| 259 | + | |
| 260 | + if VERIFY_ERRORS_IN.include? error_key | |
| 261 | + flash[flash_key] = "highlight-error" | |
| 262 | + else | |
| 263 | + flash[flash_key] = "" | |
| 264 | + end | |
| 265 | + end | |
| 258 | 266 | end |
| 259 | 267 | |
| 260 | 268 | end | ... | ... |