27 lines
		
	
	
		
			737 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
		
		
			
		
	
	
			27 lines
		
	
	
		
			737 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
|  | require 'lib/string_helper' | ||
|  | 
 | ||
|  | 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 = StringHelper.underscore_class(base) | ||
|  |         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 |