GithubHelp home page GithubHelp logo

Default block doesn't recurse about hashie HOT 6 CLOSED

hashie avatar hashie commented on June 22, 2024
Default block doesn't recurse

from hashie.

Comments (6)

isaacsanders avatar isaacsanders commented on June 22, 2024

Since h.foo is not a Hashie::Mash, it wouldn't use the block, if I understand correctly...

from hashie.

danielhopkins avatar danielhopkins commented on June 22, 2024

I think this is a miscommunication. Mash is recursive by default right?

When you inspect h.foo:

h.foo
=> <#Hashie::Mash>

It's a Mash. However, the default block that was assigned to the parent isn't carried down.

from hashie.

isaacsanders avatar isaacsanders commented on June 22, 2024

oh. yah, ignore me.... :P

from hashie.

jch avatar jch commented on June 22, 2024

If any of you are interested in sending up a pull, I'd be happy to review it!

from hashie.

fizz avatar fizz commented on June 22, 2024

I ran into a similar issue while subclassing a Hashie::Trash base class (properties were losing their :transform_with argument). I was using it to abstract requests to a really gnarly API. Solved it with an activesupport concern, works great.

DATE = lambda {|v| v.stamp('12/31/1999')}

module DateRange
  extend ActiveSupport::Concern
  included do
    property :start_date, :default => Date.today, :transform_with => DATE, :required => true
    property :end_date, :default => Date.today, :transform_with => DATE, :required => true
  end
end

class BaseRequest < Hashie::Trash
  credentials = Hashie::Mash.new(YAML::load(File.read(File.join(ENV['HOME'], '.fuglyapi'))))
  property :username, :default => credentials.username
  property :password, :default => credentials.password
end

class OrderRequest < BaseRequest
  extend ActiveSupport::Concern
  property :criteria, :default => 'all'
  property :campaign_id, :default => 'all'
end

class OrderIndexByDate < OrderRequest
  include DateRange
end

from hashie.

dblock avatar dblock commented on June 22, 2024

I am going to close this. Please reopen if you think we need to do something in Hashie for this.

from hashie.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.