From baa42b7593d84a259c071e1076e0e5b97a9489ee Mon Sep 17 00:00:00 2001 From: Derek Edwards Date: Sat, 8 Jul 2017 13:15:08 -0400 Subject: [PATCH] DRY up the Serializers --- .../export/accommodation_serializer.rb | 21 +--------------- .../export/characteristic_serializer.rb | 21 +--------------- .../export/eligibility_serializer.rb | 24 +++++++++++++++++++ .../export/trip_purpose_serializer.rb | 20 +--------------- 4 files changed, 27 insertions(+), 59 deletions(-) create mode 100644 app/serializers/export/eligibility_serializer.rb diff --git a/app/serializers/export/accommodation_serializer.rb b/app/serializers/export/accommodation_serializer.rb index 2a5bfbd0..2a559805 100644 --- a/app/serializers/export/accommodation_serializer.rb +++ b/app/serializers/export/accommodation_serializer.rb @@ -1,24 +1,5 @@ module Export - class AccommodationSerializer < ActiveModel::Serializer - attributes :code, - :phrases - - def self.collection_serialize(collection) - ActiveModelSerializers::SerializableResource.new(collection, each_serializer: self) - end - - def phrases - - words = {} - - I18n.available_locales.each do |locale| - #It is not a bug that note and question are the same. In Oneclick Legacy, there is no question - I18n.locale = locale - words[locale] = {name: TranslationEngine.translate_text(object.name), note: TranslationEngine.translate_text(object.note), question: TranslationEngine.translate_text(object.note)} - end - - words - end + class AccommodationSerializer < EligibilitySerializer end end \ No newline at end of file diff --git a/app/serializers/export/characteristic_serializer.rb b/app/serializers/export/characteristic_serializer.rb index 20ecbef4..bf2466c6 100644 --- a/app/serializers/export/characteristic_serializer.rb +++ b/app/serializers/export/characteristic_serializer.rb @@ -1,24 +1,5 @@ module Export - class CharacteristicSerializer < ActiveModel::Serializer - attributes :code, - :phrases - - def self.collection_serialize(collection) - ActiveModelSerializers::SerializableResource.new(collection, each_serializer: self) - end - - def phrases - - words = {} - - I18n.available_locales.each do |locale| - #It is not a bug that note and question are the same. In Oneclick Legacy, there is no question - I18n.locale = locale - words[locale] = {name: TranslationEngine.translate_text(object.name), note: TranslationEngine.translate_text(object.note), question: TranslationEngine.translate_text(object.note)} - end - - words - end + class CharacteristicSerializer < EligibilitySerializer end end \ No newline at end of file diff --git a/app/serializers/export/eligibility_serializer.rb b/app/serializers/export/eligibility_serializer.rb new file mode 100644 index 00000000..bc43e188 --- /dev/null +++ b/app/serializers/export/eligibility_serializer.rb @@ -0,0 +1,24 @@ +module Export + class EligibilitySerializer < ActiveModel::Serializer + attributes :code, + :phrases + + def self.collection_serialize(collection) + ActiveModelSerializers::SerializableResource.new(collection, each_serializer: self) + end + + def phrases + + words = {} + + I18n.available_locales.each do |locale| + #It is not a bug that note and question are the same. In Oneclick Legacy, there is no question + I18n.locale = locale + words[locale] = {name: TranslationEngine.translate_text(object.name), note: TranslationEngine.translate_text(object.note), question: TranslationEngine.translate_text(object.note)} + end + + words + end + + end +end \ No newline at end of file diff --git a/app/serializers/export/trip_purpose_serializer.rb b/app/serializers/export/trip_purpose_serializer.rb index 7bbb3ddd..9f4f8702 100644 --- a/app/serializers/export/trip_purpose_serializer.rb +++ b/app/serializers/export/trip_purpose_serializer.rb @@ -1,24 +1,6 @@ module Export - class TripPurposeSerializer < ActiveModel::Serializer - attributes :code, - :phrases + class TripPurposeSerializer < EligibilitySerializer - def self.collection_serialize(collection) - ActiveModelSerializers::SerializableResource.new(collection, each_serializer: self) - end - - def phrases - - words = {} - - I18n.available_locales.each do |locale| - #It is not a bug that note and question are the same. In Oneclick Legacy, there is no question - I18n.locale = locale - words[locale] = {name: TranslationEngine.translate_text(object.name), note: TranslationEngine.translate_text(object.note), question: TranslationEngine.translate_text(object.note)} - end - - words - end end end \ No newline at end of file