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,12 +11,14 @@ class ApiEntreprise::EntrepriseAdapter
end end
def to_params def to_params
if data_source.present?
params = data_source[:entreprise].slice(*attr_to_fetch) params = data_source[:entreprise].slice(*attr_to_fetch)
params[:date_creation] = Time.at(params[:date_creation]).to_datetime params[:date_creation] = Time.at(params[:date_creation]).to_datetime
params params
rescue else
nil nil
end end
end
private private

View file

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

View file

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

View file

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