From 3fa08e707fbc7899c0964bef4b501e137991d838 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Fri, 1 Jun 2018 20:41:20 +0100 Subject: Add a basic description method to GovukGuix::DataSnapshot This is for use when rendering these in a view. --- app/models/govuk_guix/data_snapshot.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'app') diff --git a/app/models/govuk_guix/data_snapshot.rb b/app/models/govuk_guix/data_snapshot.rb index ec40cc4..bdfcd7e 100644 --- a/app/models/govuk_guix/data_snapshot.rb +++ b/app/models/govuk_guix/data_snapshot.rb @@ -40,4 +40,22 @@ class GovukGuix::DataSnapshot < ApplicationRecord foreign_key: 'govuk_guix_revision_commit_hash' ) belongs_to :backend, polymorphic: true, optional: true + + def description + extracts_by_database = manifest['extracts'] + + dates = extracts_by_database.flat_map do |_, extracts| + extracts.map do |extract| + extract['datetime'] + end + end + + all_services = extracts_by_database.flat_map do |_, extracts| + extracts.map do |extract| + extract['services'] + end + end + + "#{dates.uniq.join(', ')}: #{all_services.join(', ')}" + end end -- cgit v1.2.3