diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-02-07 15:11:15 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-02-07 15:11:15 +0300 |
commit | e4cb073bc037856b3d31e79c081e7ed0d330bdc2 (patch) | |
tree | 7fbf4dc2bbfdc503d0c5424bb500d716c3446d95 /app/serializers | |
parent | 14bf5c10097a788b9971b7660c6104475fdc48fb (diff) |
Simplify implementation of environments serializer
Diffstat (limited to 'app/serializers')
-rw-r--r-- | app/serializers/environment_serializer.rb | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/app/serializers/environment_serializer.rb b/app/serializers/environment_serializer.rb index 5e8634e05d0..b615d01d4f9 100644 --- a/app/serializers/environment_serializer.rb +++ b/app/serializers/environment_serializer.rb @@ -1,5 +1,5 @@ class EnvironmentSerializer < BaseSerializer - Struct.new('Item', :name, :size, :id, :latest) + Item = Struct.new(:name, :size, :latest) entity EnvironmentEntity @@ -41,11 +41,10 @@ class EnvironmentSerializer < BaseSerializer 'COUNT(*) AS environments_count', 'MAX(id) AS last_environment_id') - environments = resource.where(id: items.map(&:last)) - .order('COALESCE(environment_type, name) ASC') + environments = resource.where(id: items.map(&:last)).index_by(&:id) - items.zip(environments).map do |item| - Struct::Item.new(*item.flatten) + items.map do |name, size, id| + Item.new(name, size, environments[id]) end end end |