fixed error with indexes if collection does not exist
This commit is contained in:
parent
947c7cdac4
commit
7b1a2c1dc5
@ -6,10 +6,24 @@ require "exceptions/invalid_privileges"
|
||||
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')
|
||||
|
||||
@ -2,7 +2,11 @@ module Connectors
|
||||
class Filter < Base
|
||||
|
||||
def initialize(db)
|
||||
self.collection = db.collection('filters')
|
||||
super(db)
|
||||
end
|
||||
|
||||
def collection_name
|
||||
'filters'
|
||||
end
|
||||
|
||||
def available_images provider
|
||||
|
||||
@ -9,7 +9,11 @@ module Connectors
|
||||
Helpers::UpdateCommand
|
||||
|
||||
def initialize(db)
|
||||
self.collection = db.collection('images')
|
||||
super(db)
|
||||
end
|
||||
|
||||
def collection_name
|
||||
'images'
|
||||
end
|
||||
|
||||
def images(provider=nil)
|
||||
|
||||
@ -7,7 +7,11 @@ module Connectors
|
||||
Helpers::DeleteCommand
|
||||
|
||||
def initialize(db)
|
||||
self.collection = db.collection('keys')
|
||||
super(db)
|
||||
end
|
||||
|
||||
def collection_name
|
||||
'keys'
|
||||
end
|
||||
|
||||
def key(id, scope=nil)
|
||||
|
||||
@ -8,7 +8,11 @@ module Connectors
|
||||
|
||||
|
||||
def initialize(db)
|
||||
@collection = db.collection('projects')
|
||||
super(db)
|
||||
end
|
||||
|
||||
def collection_name
|
||||
'projects'
|
||||
end
|
||||
|
||||
def is_project_exists?(project)
|
||||
|
||||
@ -8,7 +8,11 @@ module Connectors
|
||||
|
||||
|
||||
def initialize(db)
|
||||
@collection = db.collection('project_templates')
|
||||
super(db)
|
||||
end
|
||||
|
||||
def collection_name
|
||||
'project_templates'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -6,7 +6,11 @@ module Connectors
|
||||
Helpers::ListCommand
|
||||
|
||||
def initialize(db)
|
||||
self.collection = db.collection('reports')
|
||||
super(db)
|
||||
end
|
||||
|
||||
def collection_name
|
||||
'reports'
|
||||
end
|
||||
|
||||
def save_report r
|
||||
|
||||
@ -5,7 +5,11 @@ module Connectors
|
||||
|
||||
|
||||
def initialize(db)
|
||||
self.collection = db.collection('servers')
|
||||
super(db)
|
||||
end
|
||||
|
||||
def collection_name
|
||||
'servers'
|
||||
end
|
||||
|
||||
def servers_find(query, fields=nil)
|
||||
|
||||
@ -7,7 +7,11 @@ module Connectors
|
||||
Helpers::UpdateCommand
|
||||
|
||||
def initialize(db)
|
||||
self.collection = db.collection('stacks')
|
||||
super(db)
|
||||
end
|
||||
|
||||
def collection_name
|
||||
'stacks'
|
||||
end
|
||||
|
||||
def stacks(options={})
|
||||
|
||||
@ -8,7 +8,11 @@ module Connectors
|
||||
Helpers::UpdateCommand
|
||||
|
||||
def initialize(db)
|
||||
self.collection = db.collection('stack_templates')
|
||||
super(db)
|
||||
end
|
||||
|
||||
def collection_name
|
||||
"stack_templates"
|
||||
end
|
||||
|
||||
def stack_templates(provider=nil)
|
||||
|
||||
@ -2,7 +2,11 @@ module Connectors
|
||||
class Statistic < Base
|
||||
|
||||
def initialize(db)
|
||||
self.collection = db.collection('statistic')
|
||||
super(db)
|
||||
end
|
||||
|
||||
def collection_name
|
||||
'statistic'
|
||||
end
|
||||
|
||||
def insert_statistic(user, path, method, body, response_code)
|
||||
@ -45,7 +49,8 @@ module Connectors
|
||||
private
|
||||
|
||||
def mongo_sort_order(order)
|
||||
raise "Wrong sort order" unless %w(asc desc).include?(order)
|
||||
# asc by default and if order id invalid value, it is not a reason for response with code 500
|
||||
#raise "Wrong sort order" unless %w(asc desc).include?(order)
|
||||
order == 'asc' ? 1 : -1
|
||||
end
|
||||
|
||||
|
||||
@ -8,7 +8,11 @@ module Connectors
|
||||
Helpers::UpdateCommand
|
||||
|
||||
def initialize(db)
|
||||
self.collection = db.collection('users')
|
||||
super(db)
|
||||
end
|
||||
|
||||
def collection_name
|
||||
'users'
|
||||
end
|
||||
|
||||
def user_auth user, password
|
||||
|
||||
Loading…
Reference in New Issue
Block a user