fluke/devops-service/db/mongo/connectors/base.rb

42 lines
1.2 KiB
Ruby
Raw Normal View History

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"
2018-04-04 22:44:39 +03:00
%w(delete insert list show update).each do |command_name|
require_relative "helpers/#{command_name}_command"
end
2015-02-12 13:01:05 +03:00
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