lib/dolly/mango_index.rb in dolly-3.0.1 vs lib/dolly/mango_index.rb in dolly-3.1.0
- old
+ new
@@ -21,13 +21,17 @@
def create(name, fields, type = 'json')
post(DESIGN, build_index_structure(name, fields, type))
end
+ def create_in_database(database, name, fields, type = 'json')
+ connection_for_database(database).post(DESIGN, build_index_structure(name, fields, type))
+ end
+
def find_by_fields(fields)
rows = get(ALL_DOCS, key: key_from_fields(fields))[ROWS_KEY]
- rows && rows.any?
+ (rows && rows.any?)
end
def delete_all
all.each do |index_doc|
next if index_doc[:ddoc].nil?
@@ -39,9 +43,13 @@
resource = "#{DESIGN}/#{index_doc[:ddoc]}/json/#{index_doc[:name]}"
connection.delete(resource, escape: false)
end
private
+
+ def connection_for_database(database)
+ Dolly::Connection.new(database.to_sym, Rails.env || :development)
+ end
def connection
@connection ||= Dolly::Document.connection
end