Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Jeremy Rodi
    @medcat
    @magicalbanana on line 24, within locate_data, you call locate_data unconditionally (and since you haven't redefined it yet, it calls the method on the class), which causes a stack level error
    Grégory Horion
    @gregory
    nice! thx @dblock !
    James DeHart
    @jamesdehart

    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?

    Michael Herold
    @michaelherold

    @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"
    James DeHart
    @jamesdehart
    Cool let me give that a try.
    Works!!!!
    I so need to get new glasses.
    James DeHart
    @jamesdehart
    @michaelherold Bowing before the master
    Michael Herold
    @michaelherold
    Haha, glad to help
    James DeHart
    @jamesdehart

    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"

    Daniel (dB.) Doubrovkine
    @dblock
    Jesse Trimble
    @jtrim
    Hi! Using Hashie::Extensions::Coercion, I've got a bit of data I'm trying to coerce into 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
    Jesse Trimble
    @jtrim
    I suppose I could make a thin wrapper around BigDecimal that handles nil values in a better way for my use case
    Yep, that works. Sorry for posting a question I answered myself :\
    Gus P
    @staycreativedesign
    W, [2018-02-07T09:46:38.025179 #30973] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#count defined in Enumerable. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method.
    how can i remove this log error?
    TL;DR: set logger to something empty, or subclass Mash and disable warnings in subclass.
    Gus P
    @staycreativedesign
    @zverok where would I put that in my rails app?
    config/initializers?
    Victor Shepelev
    @zverok
    ¯\_(ツ)_/¯
    Wherever you put this kind of stuff, initializers probably.
    Gus P
    @staycreativedesign
    config/initializers/hashie.rb:1:in `<top (required)>': uninitialized constant Hashie (NameError)
    ?!@
    Victor Shepelev
    @zverok
    probably it is still not required when initializer is called. try requireing it explicitly (or google how people typically solve this, I've never did that exact thing, just theorizing)
    Gus P
    @staycreativedesign
    yep
    hashie (3.5.7) is in my gemfile.lock
        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)
    Martin Streicher
    @martinstreicher
    @staycreativedesign Are you able to rename the count field?
    The message comes from using a key in the mash that conflicts with a built-in Mash method
    I had one called cycle that I changed to avoid issues.
    Peter Fitzgibbons
    @pjfitzgibbons
    Hello! (Is this thing still on?!) IF anyone can hear me :) I'm wondering if there is a more-elegant way to use lambda coercions? Like wrap them in a class or a constant or something? Something like a coercion to/from Date is "simple" yet verbose due to the lambda and a necessary predicate/gate test on value.is_a?(Date).
    Thoughts anyone?
    Bobby McDonald
    @BobbyMcWho
    Hello, discussion will be moving to https://gitter.im/hashie/hashie