Skip to content

Commit

Permalink
DRY up the Serializers
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekEdwards committed Jul 8, 2017
1 parent c6f40b0 commit baa42b7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 59 deletions.
21 changes: 1 addition & 20 deletions app/serializers/export/accommodation_serializer.rb
Original file line number Diff line number Diff line change
@@ -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
21 changes: 1 addition & 20 deletions app/serializers/export/characteristic_serializer.rb
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions app/serializers/export/eligibility_serializer.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 1 addition & 19 deletions app/serializers/export/trip_purpose_serializer.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit baa42b7

Please sign in to comment.