Skip to content

Commit 58d4c99

Browse files
committed
add and categorize public instance methods in readme; add misc notes to readme
1 parent a5a4c62 commit 58d4c99

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

README.md

+32
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,43 @@ todo_list.first.move_to_bottom
3030
todo_list.last.move_higher
3131
```
3232

33+
## Instance Methods Added To ActiveRecord Models
34+
35+
You'll have a number of methods added to each instance of the ActiveRecord model that to which `acts_as_list` is added.
36+
37+
In `acts_as_list`, "higher" means further up the list (a lower `position`), and "lower" means further down the list (a higher `position`). That can be confusing, so it might make sense to add tests that validate that you're using the right method given your context.
38+
39+
### Methods That Change Position and Reorder List
40+
41+
- `list_item.insert_at(2)`
42+
- `list_item.move_lower` will do nothing if the item is the lowest item
43+
- `list_item.move_higher` will do nothing if the item is the highest item
44+
- `list_item.move_to_bottom`
45+
- `list_item.move_to_top`
46+
- `list_item.remove_from_list`
47+
48+
### Methods That Change Position Without Reordering List
49+
50+
- `list_item.increment_position`
51+
- `list_item.decrement_position`
52+
- `list_item.set_list_position(3)`
53+
54+
### Methods That Return Attributes of the Item's List Position
55+
- `list_item.first?`
56+
- `list_item.last?`
57+
- `list_item.in_list?`
58+
- `list_item.not_in_list?`
59+
- `list_item.default_position?`
60+
- `list_item.higher_item`
61+
- `list_item.lower_item`
62+
3363
## Notes
3464
If the `position` column has a default value, then there is a slight change in behavior, i.e if you have 4 items in the list, and you insert 1, with a default position 0, it would be pushed to the bottom of the list. Please look at the tests for this and some recent pull requests for discussions related to this.
3565

3666
All `position` queries (select, update, etc.) inside gem methods are executed without the default scope (i.e. `Model.unscoped`), this will prevent nasty issues when the default scope is different from `acts_as_list` scope.
3767

68+
The `position` column is set after validations are called, so you should not put a `presence` validation on the `position` column.
69+
3870
## Versions
3971
All versions `0.1.5` onwards require Rails 3.0.x and higher.
4072

0 commit comments

Comments
 (0)