Sha256: 875282201ed49abec458c1affdd0a5e9af8980592a0fa44146e45e2f75a256a8

Contents?: true

Size: 1.87 KB

Versions: 8

Compression:

Stored size: 1.87 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Service
    module Plugins
      module CanHaveStubbedResults
        module Commands
          class SetServiceStubbedResult < Support::Command
            ##
            # @!attribute [r] service
            #   @return [ConvenientService::Service]
            #
            attr_reader :service

            ##
            # @!attribute [r] arguments
            #   @return [ConvenientService::Support::Arguments]
            #
            attr_reader :arguments

            ##
            # @!attribute [r] result
            #   @return [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result]
            #
            attr_reader :result

            ##
            # @param service [ConvenientService::Service]
            # @param arguments [ConvenientService::Support::Arguments]
            # @param result [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result]
            # @return [void]
            #
            def initialize(service:, arguments:, result:)
              @service = service
              @arguments = arguments
              @result = result
            end

            ##
            # @return [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result]
            #
            def call
              cache.write(key, result)
            end

            private

            ##
            # @return [ConvenientService::Support::Cache]
            #
            def cache
              @cache ||= Commands::FetchServiceStubbedResultsCache.call(service: service)
            end

            ##
            # @return [ConvenientService::Support::Cache::Entities::Key]
            #
            def key
              @key ||= cache.keygen(*arguments.args, **arguments.kwargs, &arguments.block)
            end
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
convenient_service-0.19.1 lib/convenient_service/service/plugins/can_have_stubbed_results/commands/set_service_stubbed_result.rb
convenient_service-0.19.0 lib/convenient_service/service/plugins/can_have_stubbed_results/commands/set_service_stubbed_result.rb
convenient_service-0.18.0 lib/convenient_service/service/plugins/can_have_stubbed_results/commands/set_service_stubbed_result.rb
convenient_service-0.17.0 lib/convenient_service/service/plugins/can_have_stubbed_results/commands/set_service_stubbed_result.rb
convenient_service-0.16.0 lib/convenient_service/service/plugins/can_have_stubbed_results/commands/set_service_stubbed_result.rb
convenient_service-0.15.0 lib/convenient_service/service/plugins/can_have_stubbed_results/commands/set_service_stubbed_result.rb
convenient_service-0.14.0 lib/convenient_service/service/plugins/can_have_stubbed_results/commands/set_service_stubbed_result.rb
convenient_service-0.13.0 lib/convenient_service/service/plugins/can_have_stubbed_results/commands/set_service_stubbed_result.rb