CDLUC3/resync-client

View on GitHub
lib/resync/client/mixins/client_delegator.rb

Summary

Maintainability
A
0 mins
Test Coverage
require 'resync/client'

module Resync
  class Client
    module Mixins
      # An object that delegates to another to provide a {Client} for downloading
      # resources and links.
      #
      # @!attribute [rw] client_delegate
      #   @return [#client] The client provider.
      module ClientDelegator
        attr_accessor :client_delegate

        def client
          client_delegate.client
        end

        # Creates a one-off delegate wrapper around the specified {Client}
        # @param value [Client] the client
        def client=(value)
          @client_delegate = ClientDelegate.new(value)
        end

        # Minimal 'delegate' wrapper around a specified {Client}
        class ClientDelegate
          # @return [#client] the client
          attr_reader :client

          # Creates a new {ClientDelegate} wrapping the specified {Client}
          # @param client The client to delegate to
          def initialize(client)
            @client = client
          end
        end
      end
    end
  end
end