Sha256: 47f61ffb44d10f0518bb1e5694190f742379a1506e6c7091a6dc84ff58c19af3

Contents?: true

Size: 511 Bytes

Versions: 6

Compression:

Stored size: 511 Bytes

Contents

require 'hashie'

module Faraday
  class Response::Mashify < Response::Middleware
    def self.register_on_complete(env)
      env[:response].on_complete do |response|
        json = response[:body]
        if json.is_a?(Hash)
          response[:body] = Hashie::Mash.new(json)
        elsif json.is_a?(Array) and json.first.is_a?(Hash)
          response[:body] = json.map{|item| Hashie::Mash.new(item) }
        end
      end
    end

    def initialize(app)
      super
      @parser = nil
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
faraday_middleware-0.1.4 lib/faraday/mashify.rb
faraday_middleware-0.1.3 lib/faraday/mashify.rb
faraday_middleware-0.1.2 lib/faraday/mashify.rb
faraday_middleware-0.1.1 lib/faraday/mashify.rb
faraday_middleware-0.1.0 lib/faraday/mashify.rb
faraday_middleware-0.0.5 lib/faraday/mashify.rb