| 
									
										
										
										
											2015-07-16 17:18:55 +03:00
										 |  |  | require "exceptions/record_not_found" | 
					
						
							|  |  |  | require "exceptions/invalid_record" | 
					
						
							| 
									
										
										
										
											2015-02-12 13:01:05 +03:00
										 |  |  | require "exceptions/invalid_command" | 
					
						
							|  |  |  | require "exceptions/invalid_privileges" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module Connectors | 
					
						
							|  |  |  |   class Base | 
					
						
							| 
									
										
										
										
											2015-09-15 14:27:06 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-21 15:54:33 +03:00
										 |  |  |     # если хотим создавать индексы при старте приложения, нужно сначала создать коллекцию | 
					
						
							|  |  |  |     def initialize db | 
					
						
							|  |  |  |       names = db.collection_names | 
					
						
							|  |  |  |       unless names.include?(self.collection_name) | 
					
						
							|  |  |  |         db.create_collection(self.collection_name) | 
					
						
							|  |  |  |         puts "Collection '#{self.collection_name}' has been created" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       self.collection = db.collection(self.collection_name) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-15 14:27:06 +03:00
										 |  |  |     def create_indexes | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-21 15:54:33 +03:00
										 |  |  |     def collection_name | 
					
						
							|  |  |  |       raise "owerride me" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-12 13:01:05 +03:00
										 |  |  |     # Yes, we can implement connectors without attr_accessor, storing collection directly | 
					
						
							|  |  |  |     # in instance variable like | 
					
						
							|  |  |  |     # @collection = db.collection('users') | 
					
						
							|  |  |  |     # | 
					
						
							|  |  |  |     # But with latter approach included modules should know about instance variables of | 
					
						
							|  |  |  |     # base classes. | 
					
						
							|  |  |  |     # Also, debugging "No method error" is simplier than seeking missing instance var. | 
					
						
							|  |  |  |   private | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     attr_accessor :collection | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |