23 lines
		
	
	
		
			648 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			23 lines
		
	
	
		
			648 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| module Connectors
 | |
|   module Helpers
 | |
|     module UpdateCommand
 | |
| 
 | |
|       # this module adds methods #update and "#{resource_name}_update" (they are synonyms).
 | |
|       # We need second method name to forward methods from MongoConnector to resources connectors.
 | |
| 
 | |
|       def self.included(base)
 | |
|         method_name = "#{base.to_s.underscore_class}_update".to_sym
 | |
|         alias_method method_name, :update
 | |
|       end
 | |
| 
 | |
|       def update(record)
 | |
|         record.validate!
 | |
|         r = collection.update({"_id" => record.id}, record.to_mongo_hash)
 | |
|         raise RecordNotFound.new("'#{record.id}' not found") if r['n'] == 0
 | |
|         record
 | |
|       end
 | |
| 
 | |
|     end
 | |
|   end
 | |
| end
 | 
