25 lines
		
	
	
		
			699 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			25 lines
		
	
	
		
			699 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| module Connectors
 | |
|   module Helpers
 | |
|     module DeleteCommand
 | |
| 
 | |
|       # when included, this module adds method #delete and alias for it.
 | |
|       # Alias name depends on base class name.
 | |
|       # We need this alias to forward methods from MongoConnector to resources connectors.
 | |
| 
 | |
|       def self.included(base)
 | |
|         resource_name = base.to_s.underscore_class
 | |
|         method_name = "#{resource_name}_delete".to_sym
 | |
|         alias_method method_name, :delete
 | |
|       end
 | |
| 
 | |
|       def delete(id, options={})
 | |
|         delete_query = {'_id' => id}.merge(options)
 | |
|         r = collection.remove(delete_query)
 | |
|         raise RecordNotFound.new("'#{id}' not found") if r['n'] == 0
 | |
|         r
 | |
|       end
 | |
| 
 | |
|     end
 | |
|   end
 | |
| end
 | 
