mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-31 21:37:16 +00:00
Extract ids_to_objs to SerializerHelper
This commit is contained in:
6
app/helpers/serializer_helper.rb
Normal file
6
app/helpers/serializer_helper.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module SerializerHelper
|
||||
def ids_to_objs(ids)
|
||||
return [] if ids.blank?
|
||||
ids.map { |id| {id: id} }
|
||||
end
|
||||
end
|
||||
@@ -20,6 +20,8 @@ class Api::EnterpriseSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
include SerializerHelper
|
||||
|
||||
attributes :orders_close_at, :active
|
||||
has_many :supplied_properties, serializer: Api::PropertySerializer
|
||||
has_many :distributed_properties, serializer: Api::PropertySerializer
|
||||
@@ -59,6 +61,8 @@ class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
include SerializerHelper
|
||||
|
||||
cached
|
||||
#delegate :cache_key, to: :object
|
||||
|
||||
@@ -161,12 +165,4 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
}
|
||||
icon_fonts[object.category]
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def ids_to_objs(ids)
|
||||
return [] if ids.blank?
|
||||
ids.map { |id| {id: id} }
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user