README.md in acts_as_belongable-1.0.0 vs README.md in acts_as_belongable-1.1.0

- old
+ new

@@ -12,10 +12,11 @@ * [Usage](#usage) * [Associations](#associations) * [acts_as_belonger](#acts_as_belonger) * [acts_as_belongable](#acts_as_belongable) * [acts_as_list](#acts_as_list) + * [Scopes](#scopes) * [To Do](#to-do) * [Contributing](#contributing) * [Contributors](#contributors) * [Semantic versioning](#semantic-versioning) * [License](#license) @@ -119,9 +120,50 @@ acts_as_belongable integrates with [acts_as_list](). It adds a `position` column to `Belonging`: ```ruby c.add_belongable Event.first, position: 1 +``` + +### Scopes + +You can use scopes to add details to an relation: + +```ruby +u = User.first +e = u.create_belongable 'Event' +c = u.create_belongable 'Conference' +u = User.last +u.add_belongable 'Event', scope: 'collaboration' +u.add_belongable 'Conference', scope: 'collaboration' + +# Get all belongables with a specific scope +u.belongables_with_scope :collaboration + +# Get `Event` belongables with a specific scope +u.belongables_with_scope :collaboration, 'Event' + +# Get all belongers with a specific scope +e.belongers_with_scope :collaboration + +# Get `User` belongers with a specific scope +e.belongers_with_scope :collaboration, 'User' +``` + +You are also able to restrict associations to specific scopes: + +```ruby +class User < ApplicationRecord + acts_as_belonger + belonger :conference_collaborations, 'Conference', scope: :collaboration + belonger :conference_attendings, 'User', scope: :membership +end + +class Conference < ApplicationRecord + acts_as_belongable + belongable :collaborators, 'User', scope: :collaboration + belongable :attendees, 'User', scope: :membership +end ``` --- ## To Do