Created
September 3, 2015 15:44
-
-
Save elrayle/d9519b1e1010acdb6a7f to your computer and use it in GitHub Desktop.
AddMembersToCollection service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Hydra | |
| module Collections | |
| class AddMembersToCollection | |
| ## | |
| # Add members to a collection. | |
| # | |
| # @param [Collection] :collection to which to add members | |
| # @param [Object] :new_member_ids being added | |
| # | |
| # @return [Collection] the updated collection | |
| def self.call(collection, new_member_ids, persist= false) | |
| collection = Collection.find(collection) if collection.is_a? String | |
| raise ArgumentError, "collection (#{collection}) not found" if collection.nil? | |
| raise ArgumentError, 'collection must be a Collection' unless collection.is_a? Collection | |
| collection.member_ids = new_member_ids.concat(collection.member_ids) | |
| collection.save if persist | |
| end | |
| end | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
6.3 code in collections_controller_behavior.rb
pcdm code in collections_controller_behavior.rb
For both becomes the following...