Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default block doesn't recurse #26

Closed
danielhopkins opened this issue Nov 21, 2011 · 6 comments
Closed

Default block doesn't recurse #26

danielhopkins opened this issue Nov 21, 2011 · 6 comments

Comments

@danielhopkins
Copy link

>> h = Hashie::Mash.new({:foo => {}}){raise 'missing method'}
=> <#Hashie::Mash foo=<#Hashie::Mash>>
>> h.foo
=> <#Hashie::Mash>
>> h.bar
RuntimeError: missing method
>> h.foo.bar
=> nil

I believe that last line should throw an exception.

@isaacsanders
Copy link

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

@danielhopkins
Copy link
Author

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.

@isaacsanders
Copy link

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

@jch
Copy link
Contributor

jch commented Feb 13, 2013

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

@fizz
Copy link

fizz commented Jun 24, 2013

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

@dblock
Copy link
Member

dblock commented Mar 31, 2014

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

@dblock dblock closed this as completed Mar 31, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants