Sha256: 4acfb7cc7e5248d4cdaad13bea8a6a27420a916731a26e7e819b0665f82642ab

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Service
    module Plugins
      module HasResultMethodSteps
        class Middleware < Core::MethodChainMiddleware
          ##
          # @internal
          #   NOTE: It is okish to assign to next method arguments here,
          #   since splat for `args` and double splat for `kwargs`
          #   always create new arrays and hashes respectively.
          #   https://github.com/ruby/spec/blob/c7ed8478a031d0df346d222495f4b4bbb298523b/language/keyword_arguments_spec.rb#L100
          #
          def next(*args, **kwargs, &block)
            return chain.next(*args, **kwargs, &block) unless args.first.instance_of?(::Symbol)

            kwargs[:in] = Utils::Array.wrap(kwargs[:in]) + [{method_name: raw(args.first)}, {organizer: :itself}]

            args[0] = (args.first == :result) ? Services::RunOwnMethodInOrganizer : Services::RunMethodInOrganizer

            chain.next(*args, **kwargs, &block)
          end

          private

          ##
          # TODO: `Plugins::HasResultSteps::Entities::Method.raw_value`.
          #
          def raw(object)
            Plugins::HasResultSteps::Entities::Method::Entities::Values::Raw.wrap(object)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
convenient_service-0.3.1 lib/convenient_service/service/plugins/has_result_method_steps/middleware.rb
convenient_service-0.3.0 lib/convenient_service/service/plugins/has_result_method_steps/middleware.rb
convenient_service-0.2.1 lib/convenient_service/service/plugins/has_result_method_steps/middleware.rb
convenient_service-0.2.0 lib/convenient_service/service/plugins/has_result_method_steps/middleware.rb