Sha256: ad092d64c3e479dfc463c92934d0c9b4adc32b57206ad64787a040991a6ea032

Contents?: true

Size: 907 Bytes

Versions: 15

Compression:

Stored size: 907 Bytes

Contents

# frozen_string_literal: true

module ConvenientService
  module Common
    module Plugins
      module NormalizesEnv
        ##
        # - Single splat `*` converts `nil` to empty array.
        # - Double splat `**` raises on `nil`.
        # - Umpersand `&` converts `nil` to `nil`.
        #
        # The following middleware converts `env[:kwargs]` to a hash.
        # This way `stack.call(*env[:args], **env[:kwargs], &env[:block])` won't fail even if a user passes `nil` as `kwargs`.
        #
        # Check the following link for more details:
        # - https://bugs.ruby-lang.org/issues/8507
        #
        class Middleware < Core::ClassicMiddleware
          def call(env = nil)
            env = env.to_h
            env = env.merge(args: env[:args].to_a, kwargs: env[:kwargs].to_h, block: env[:block])

            stack.call(env)
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
convenient_service-0.12.0 lib/convenient_service/common/plugins/normalizes_env/middleware.rb
convenient_service-0.11.0 lib/convenient_service/common/plugins/normalizes_env/middleware.rb
convenient_service-0.10.1 lib/convenient_service/common/plugins/normalizes_env/middleware.rb
convenient_service-0.10.0 lib/convenient_service/common/plugins/normalizes_env/middleware.rb
convenient_service-0.9.0 lib/convenient_service/common/plugins/normalizes_env/middleware.rb
convenient_service-0.8.0 lib/convenient_service/common/plugins/normalizes_env/middleware.rb
convenient_service-0.7.0 lib/convenient_service/common/plugins/normalizes_env/middleware.rb
convenient_service-0.6.0 lib/convenient_service/common/plugins/normalizes_env/middleware.rb
convenient_service-0.5.0 lib/convenient_service/common/plugins/normalizes_env/middleware.rb
convenient_service-0.4.0 lib/convenient_service/common/plugins/normalizes_env/middleware.rb
convenient_service-0.3.1 lib/convenient_service/common/plugins/normalizes_env/middleware.rb
convenient_service-0.3.0 lib/convenient_service/common/plugins/normalizes_env/middleware.rb
convenient_service-0.2.1 lib/convenient_service/common/plugins/normalizes_env/middleware.rb
convenient_service-0.2.0 lib/convenient_service/common/plugins/normalizes_env/middleware.rb
convenient_service-0.1.0 lib/convenient_service/common/plugins/normalizes_env/middleware.rb