Sha256: 4b6c5ab38d91275f3f22ee99273da6a17e2b8c69c164c3e339d53b6665667bc3

Contents?: true

Size: 543 Bytes

Versions: 42

Compression:

Stored size: 543 Bytes

Contents

module ActionSubscriber
  module Middleware
    class Decoder
      attr_reader :env

      def initialize(app)
        @app = app
      end

      def call(env)
        @env = env

        env.payload = decoder? ? decoder.call(encoded_payload) : encoded_payload.dup

        @app.call(env)
      end

      private

      def decoder
        ::ActionSubscriber.config.decoder[env.content_type]
      end

      def decoder?
        decoder.present?
      end

      def encoded_payload
        env.encoded_payload
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
action_subscriber-5.3.3-java lib/action_subscriber/middleware/decoder.rb
action_subscriber-5.3.3 lib/action_subscriber/middleware/decoder.rb
action_subscriber-5.3.2-java lib/action_subscriber/middleware/decoder.rb
action_subscriber-5.3.2 lib/action_subscriber/middleware/decoder.rb
action_subscriber-5.3.1-java lib/action_subscriber/middleware/decoder.rb
action_subscriber-5.3.1 lib/action_subscriber/middleware/decoder.rb
action_subscriber-5.3.1.pre-java lib/action_subscriber/middleware/decoder.rb
action_subscriber-5.3.1.pre lib/action_subscriber/middleware/decoder.rb
action_subscriber-5.3.0-java lib/action_subscriber/middleware/decoder.rb
action_subscriber-5.3.0 lib/action_subscriber/middleware/decoder.rb
action_subscriber-5.2.4-java lib/action_subscriber/middleware/decoder.rb
action_subscriber-5.2.4 lib/action_subscriber/middleware/decoder.rb
action_subscriber-5.2.3-java lib/action_subscriber/middleware/decoder.rb
action_subscriber-5.2.3 lib/action_subscriber/middleware/decoder.rb
action_subscriber-5.2.2-java lib/action_subscriber/middleware/decoder.rb
action_subscriber-5.2.2 lib/action_subscriber/middleware/decoder.rb
action_subscriber-5.2.1-java lib/action_subscriber/middleware/decoder.rb
action_subscriber-5.2.1 lib/action_subscriber/middleware/decoder.rb
action_subscriber-5.2.0-java lib/action_subscriber/middleware/decoder.rb
action_subscriber-5.2.0 lib/action_subscriber/middleware/decoder.rb