Sha256: bba4a13b8ed0b9dc89c4395e9379217a50b8e645877e198faad8fbcc40ad7016

Contents?: true

Size: 685 Bytes

Versions: 2

Compression:

Stored size: 685 Bytes

Contents

module Faraday
  class Response
    # FlattenBody is a middleware that flattens the response body, and also extends
    # Hashie::Mash instances with a module that allows them to work properly with DelegateClass.
    class FlattenBody < Response::Middleware
      dependency 'hashie/mash'

      def parse(body)
        return body unless body.respond_to?(:to_a)
        flattened_response = body.to_a.flatten
        flattened_response.keep_if { |item| ::Hashie::Mash === item }
        flattened_response.map do |mash|
          # extend so that #respond_to? works nicely with DelegateClass
          mash.extend(LetsFreckle::Extensions::Mash)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
letsfreckle-client-0.2.1 lib/faraday/response/flatten_body.rb
letsfreckle-client-0.2.0 lib/faraday/response/flatten_body.rb