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

Add tree_view method #561

Merged
merged 2 commits into from
Jan 5, 2022
Merged

Add tree_view method #561

merged 2 commits into from
Jan 5, 2022

Conversation

Bizcho
Copy link
Contributor

@Bizcho Bizcho commented Nov 23, 2021

This adds the funcionality for: #559.
For Example:

arrange method:

message.subtree.arrange
{#<Message:0x000055f62357a930 id: 9, content: "This is a root message", created_at: Tue, 23 Nov 2021 05:04:04.053540000 UTC +00:00, updated_at: Tue, 23 Nov 2021 05:04:04.053540000 UTC +00:00, ancestry: nil>=>
  {#<Message:0x000055f62357a048 id: 10, content: "this is a reply", created_at: Tue, 23 Nov 2021 05:04:50.832312000 UTC +00:00, updated_at: Tue, 23 Nov 2021 05:04:50.832312000 UTC +00:00, ancestry: "9">=>
    {#<Message:0x000055f623578b58 id: 12, content: "this is a reply to a rply", created_at: Tue, 23 Nov 2021 05:05:48.845504000 UTC +00:00, updated_at: Tue, 23 Nov 2021 05:05:48.845504000 UTC +00:00, ancestry: "9/10">=>{}},
   #<Message:0x000055f6235796c0 id: 11, content: "this is another reply", created_at: Tue, 23 Nov 2021 05:05:00.767846000 UTC +00:00, updated_at: Tue, 23 Nov 2021 05:05:00.767846000 UTC +00:00, ancestry: "9">=>
    {}
  }
}

tree_view method:

message.subtree.tree_view(:content)
This is a root message
 |_ this is a reply
 |   |_ this is a reply to a rply
 |_ this is another reply

@kbrock
Copy link
Collaborator

kbrock commented Nov 24, 2021

So this is a pretty print kind of thing?

It looks nice

@Bizcho
Copy link
Contributor Author

Bizcho commented Dec 3, 2021

Yes a friend of mine is using this gem for nesting components and wanted a better way of debuggin the tree. Hope it gets added to the main repo

git history can point people to any issues handled by this pr
@kbrock kbrock merged commit b55397b into stefankroes:master Jan 5, 2022
@kbrock
Copy link
Collaborator

kbrock commented Jan 5, 2022

thanks

@kbrock
Copy link
Collaborator

kbrock commented Mar 18, 2022

@Bizcho Hey,

Do you have any docs on using this?
/cc @epugh

@Bizcho
Copy link
Contributor Author

Bizcho commented Mar 19, 2022

Hello @kbrock I dont have any Docs but the basic idea is to call the method tree_view and pass a symbold that is a property od the class you are using. like in the first coment.

Class Message has two atributes id and content, So you could call
message.subtree.tree_view(:content)
or
message.subtree.tree_view(:id)

the result is built with the toString() of whaterever atribute you passed to the method

hope my awnser is sufficent,

@epugh
Copy link

epugh commented Mar 21, 2022

I unfortunantly get:

ERROR TriesAncestryLifecycleTest#test_create_200_tries_behavior (1.25s)
Minitest::UnexpectedError:         NoMethodError: undefined method `tree_view' for #<ActiveRecord::Relation []>
            test/integration/tries_ancestry_lifecycle_test.rb:21:in `block in <class:TriesAncestryLifecycleTest>'

Here is the (commented out!) use of this command: https://github.com/o19s/quepid/blob/ancestry_column_too_short/test/integration/tries_ancestry_lifecycle_test.rb#L21

@kbrock
Copy link
Collaborator

kbrock commented Mar 31, 2022

@epugh I'm curious, is the ancestry column getting properly in your test?
i.e. If you add a puts try.ancestry after the try.save! does it keep getting longer and longer?

also the use of the try variable is fine, but it does make me nervous for the try() method defined via ActiveSupport

Could you paste the code that is failing for you?
That link no longer shows the line commented out

kbrock added a commit to kbrock/ancestry that referenced this pull request Jun 10, 2022
* added strategy: materialized_path2 stefankroes#571
* Added tree_view method stefankroes#561 (thx @Bizcho)
* Fixed bug when errors would not undo callbacks stefankroes#566 (thx @daniloisr)
* ruby 3.0 support
* rails 7.0 support (thx @chenillen, @petergoldstein)
* Documentation fixes (thx @benkoshy, @mijoharas)
@kbrock kbrock mentioned this pull request Jun 10, 2022
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.

3 participants