Use if-flows instead of rescue-flows

This commit is contained in:
gregoirenovel 2018-03-15 14:41:04 +01:00
parent 182afee970
commit 19add3f534
4 changed files with 31 additions and 23 deletions

View file

@ -11,11 +11,13 @@ class ApiEntreprise::EntrepriseAdapter
end end
def to_params def to_params
params = data_source[:entreprise].slice(*attr_to_fetch) if data_source.present?
params[:date_creation] = Time.at(params[:date_creation]).to_datetime params = data_source[:entreprise].slice(*attr_to_fetch)
params params[:date_creation] = Time.at(params[:date_creation]).to_datetime
rescue params
nil else
nil
end
end end
private private

View file

@ -11,13 +11,15 @@ class ApiEntreprise::EtablissementAdapter
end end
def to_params def to_params
params = data_source[:etablissement].slice(*attr_to_fetch) if data_source.present?
adresse_line = params[:adresse].slice(*address_lines_to_fetch).values.compact.join("\r\n") params = data_source[:etablissement].slice(*attr_to_fetch)
params.merge!(params[:adresse].slice(*address_attr_to_fetch)) adresse_line = params[:adresse].slice(*address_lines_to_fetch).values.compact.join("\r\n")
params[:adresse] = adresse_line params.merge!(params[:adresse].slice(*address_attr_to_fetch))
params params[:adresse] = adresse_line
rescue params
nil else
nil
end
end end
private private

View file

@ -5,11 +5,13 @@ class ApiEntreprise::ExercicesAdapter
end end
def to_array def to_array
data_source[:exercices].map do |exercice| if data_source.present?
exercice.slice(*attr_to_fetch) data_source[:exercices].map do |exercice|
exercice.slice(*attr_to_fetch)
end
else
[]
end end
rescue
[]
end end
private private

View file

@ -5,14 +5,16 @@ class ApiEntreprise::RNAAdapter
end end
def to_params def to_params
if data_source[:association][:id].nil? if data_source.present?
return nil if data_source[:association][:id].nil?
return nil
end
params = data_source[:association].slice(*attr_to_fetch)
params[:rna] = data_source[:association][:id]
params
else
nil
end end
params = data_source[:association].slice(*attr_to_fetch)
params[:rna] = data_source[:association][:id]
params
rescue
nil
end end
private private