Skip to content

Use build_nested_hash to create hash trees #34

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

Merged
merged 3 commits into from
Dec 31, 2012

Conversation

elskwid
Copy link
Contributor

@elskwid elskwid commented Dec 30, 2012

Comments and code from: elskwid@a57b3b8

This implements build_nested_hash method that takes a block that returns a scope and makes a pretty nested hash. A few tweaks in this version,

  • Returns an empty hash if a block is not given this is just a little clearer using return instead of the if
  • Class method is a little noisier given we're working with the nested select
  • Default limit_depth is removed as discussed here: elskwid@a57b3b8#commitcomment-2367578

Nested hash call each on the scope returned from 
the block. Pass an optional root to start the 
tree from a specific point.
@elskwid
Copy link
Contributor Author

elskwid commented Dec 31, 2012

Updated and rebased against master. Just waiting on the ever-faithful-travis-workers.

@mceachen
Copy link
Collaborator

Right on. I'm trying to get the scope for hash_tree available to the test, because I want to assert that scope.size.should == scope.to_a.uniq.size (which is silly, sorta, but I think the query is scary enough to add this assertion.

If I make the scope a parameter passed to your new method, I can make my target class include a new module that lets me intercept the scope and make the assertion (or I could add a dev dependency on rr or mocha or something else and figure out how to make those do my bidding).

@mceachen
Copy link
Collaborator

OMG I LED YOU ASTRAY

Postgres takes a dump on the subselect, "column "depth" does not exist"

OK THAT'S IT LET'S SWITCH TO NOSQL.

@elskwid
Copy link
Contributor Author

elskwid commented Dec 31, 2012

Text file support inbound.

@elskwid
Copy link
Contributor Author

elskwid commented Dec 31, 2012

Annnnd, we're back.

@mceachen mceachen merged commit 1307c2b into ClosureTree:master Dec 31, 2012
@elskwid elskwid deleted the build-nested-hash branch January 1, 2013 01:19
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

Successfully merging this pull request may close these issues.

2 participants