42 lines
1.2 KiB
Ruby
42 lines
1.2 KiB
Ruby
require "exceptions/record_not_found"
|
|
require "exceptions/invalid_record"
|
|
require "exceptions/invalid_command"
|
|
require "exceptions/invalid_privileges"
|
|
%w(delete insert list show update).each do |command_name|
|
|
require_relative "helpers/#{command_name}_command"
|
|
end
|
|
|
|
module Connectors
|
|
class Base
|
|
|
|
# если хотим создавать индексы при старте приложения, нужно сначала создать коллекцию
|
|
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
|
|
|
|
def create_indexes
|
|
|
|
end
|
|
|
|
def collection_name
|
|
raise "owerride me"
|
|
end
|
|
|
|
# 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
|