Sha256: 3fda0f498a69521e81174517b4a7668a6213cb3bd671a01e433ce9249d17d08e

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

require 'active_support'
require 'active_support/core_ext/object/blank'

module Dragnet
  module Exporters
    module Serializers
      # Serializes a +Repo+ object into a +Hash+
      class RepoSerializer
        attr_reader :repo

        # @param [Dragnet::Repo] repo The +Repo+ object to serialize.
        def initialize(repo)
          @repo = repo
        end

        # Serializes the given +Repo+ object.
        # @return [Hash] A +Hash+ representing the given +Repo+ object.
        def serialize
          {
            path: repo.path,
            sha1: repo.sha1
          }.tap do |hash|
            hash[:files] = serialize_files if repo.files.present?
          end
        end

        private

        # Serializes the array of files attached to the +Repo+
        # @return [Array<String>] The array of file names (without the path to
        #   the repository).
        def serialize_files
          repo.files.map { |file| file.to_s.gsub("#{repo.path}/", '') }
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dragnet-5.3.1 lib/dragnet/exporters/serializers/repo_serializer.rb
dragnet-5.3.0 lib/dragnet/exporters/serializers/repo_serializer.rb
dragnet-5.2.1 lib/dragnet/exporters/serializers/repo_serializer.rb