Fyi, just released 3.4.1.
3.4.1 (3/31/2015)
#269: Added Hashie::Extensions::DeepLocate - @msievers.
#270: Fixed ArgumentError raised when using IndifferentAccess and HashWithIndifferentAccess - @gardenofwine.
#281: Added #reverse_merge to Mash to override ActiveSupport's version - @mgold.
#282: Fixed coercions in a subclass accumulating in the superclass - @maxlinc, @martinstreicher.
Hey All, I have a bit of a problem and I'm unable to find what I need. I'm newer to ruby so please forgive me. here is my API response that I get from rest client: "{\"status\":0,\"value\":{\"build\":{\"version\":\"1.4.8\",\"revision\":\"c8179bd8352d3c62d98fa58b324491230df9342a\"}}}"
I placed this into a HASH and then tried to use Hashie to assign the "version" to a attribute to a class.
What I come up with is
var.deep_fetch :value, :build, :version
=> "1.4.8"
What I was hoping to be able to assign the attributes a cleaner way. IDEAS?
@xsmaster You could try using #deep_find instead.
https://github.com/intridea/hashie/blob/master/lib/hashie/extensions/deep_find.rb
So it would look something like:
hash.extend(Hashie::Extensions::DeepFind)
hash.deep_find(:version) #=> "1.4.8"
So i found this out. (RTFM)
var.deep_find_all(:version)1
var = {:status=>0, :value=>{:build=>{:version=>"1.4.8", :revision=>"c8179bd8352d3c62d98fa58b324491230df9342a"}, :build2=>{:version=>"1.4.9", :revision=>"c8179bd8352d3c6"}}}
"1.4.9"
Hash[String => Hash[String => BigDecimal]]
, but the BigDecimal
part of that can also be nil - is there a way to handle that scenario that I'm missing (other than creating new classes to coerce to)? Getting Hashie::CoercionError: Cannot coerce property :property_name from Hash to {String=>{String=>BigDecimal}}: no implicit conversion of nil into String
when I hit a nil value in that BigDecimal field
instagram (1.1.6)
faraday (>= 0.7, < 0.10)
faraday_middleware (>= 0.8, < 0.10)
hashie (>= 0.4.0)
multi_json (~> 1.0, >= 1.0.3)
cycle
that I changed to avoid issues.