Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updated mashify to handle non-hashes

  • Loading branch information...
commit 997dcebc066070cb8b938fd43b03298d4da2fdb0 1 parent 6088c87
@pengwynn pengwynn authored
View
10 CHANGELOG.md
@@ -0,0 +1,10 @@
+# Changelog
+
+### 0.0.2 September 25, 2010
+
+* Mashify now handles arrays of non-hashes
+
+### 0.0.1 June 27, 2010
+
+* MultiJSON
+* Mashify
View
2  lib/faraday/mashify.rb
@@ -8,7 +8,7 @@ def self.register_on_complete(env)
json = finished_env[:body]
if json.is_a?(Hash)
finished_env[:body] = Hashie::Mash.new(json)
- elsif json.is_a?(Array)
+ elsif json.is_a?(Array) and json.first.is_a?(Hash)
finished_env[:body] = json.map{|item| Hashie::Mash.new(item) }
end
end
View
2  lib/faraday_middleware.rb
@@ -1,7 +1,7 @@
require 'faraday'
module FaradayMiddleware
- VERSION = "0.0.1".freeze
+ VERSION = "0.0.2".freeze
end
directory = File.expand_path(File.dirname(__FILE__))
View
7 test/mashify_test.rb
@@ -24,5 +24,12 @@ class MashifyTest < Test::Unit::TestCase
us.first.username.should == 'pengwynn'
us.last.username.should == 'jnunemaker'
end
+
+ should 'handle arrays of non-hashes' do
+ @stubs.get('/array/simple') { [200, {}, "[123, 456]" ] }
+ values = @conn.get("/array/simple").body
+ values.first.should == 123
+ values.last.should == 456
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.