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

Why is add_to_list_bottom private? #187

Closed
kyledecot opened this issue Feb 18, 2016 · 5 comments
Closed

Why is add_to_list_bottom private? #187

kyledecot opened this issue Feb 18, 2016 · 5 comments

Comments

@kyledecot
Copy link

Just curious as to why add_to_list_bottom is a private method? What's the proper way to add an item to a list?

@kyledecot kyledecot changed the title Why is add_to_list_bottom Why is add_to_list_bottom private? Feb 18, 2016
@brendon
Copy link
Owner

brendon commented Feb 19, 2016

I'm not sure to be fair. Given it's all mixed into your class, you could still use it within your model without problems right?

An item will automatically be added to the list (based on your configured scope) automatically. Wether it's bottom or top is configurable.

I find with acts_as_list, your best bet is to peruse the actual source code. It's just one file and is a bit more enlightening than the README in some instances: https://github.com/swanandp/acts_as_list/blob/master/lib/acts_as_list/active_record/acts/list.rb

@brendon brendon closed this as completed Feb 19, 2016
@kyledecot
Copy link
Author

@brendon the only way to invoke it from outside of the object is by using send. I have in fact looked at the source code which is what prompted this question. remove_from_list is public but it's counterparts add_to_list_bottom and add_to_list_top are not. Would a pull request to make these public be accepted?

@brendon
Copy link
Owner

brendon commented Feb 21, 2016

Hi @kyledecot, aal's default behaviour it to add an item to the bottom of the list when it is persisted to the database. There is the insert_at method that will by default add the item to the top of the list. There doesn't seem to be an equivalent method for adding to the bottom as you say. Then there's move_to_top and move_to_bottom once the item is in the list.

I wouldn't be confident accepting a pull request for making those methods public without others chiming in on this. I'm sure there was a good reason for it in the past.

@kyledecot
Copy link
Author

There doesn't seem to be an equivalent method for adding to the bottom as you say.

@brendon add_to_list_bottom and add_to_list_top

@brendon
Copy link
Owner

brendon commented Feb 22, 2016

@kyledecot, I meant a public method :)

I've had a look back. The methods have always been private (since 2007 when the code was committed). They're used internally when saving a new instance in order to add that instance to the list.

Can you give a use-case for using the method externally?

I understand your frustration, bear with me while I do due diligence on this.

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

2 participants