class Moped::Indexes
Constants
- OPTIONS
Public Instance Methods
[](key)
click to toggle source
# File lib/patches/db_commands.rb, line 47 def [](key) list_indexes_command.detect do |index| (index['name'] == key) || (index['key'] == normalize_keys(key)) end end
create(key, options = {})
click to toggle source
# File lib/patches/db_commands.rb, line 53 def create(key, options = {}) spec = options.reduce({}) do |transformed, (key, value)| transformed[OPTIONS[key.to_sym]] = value if OPTIONS[key.to_sym] transformed end spec = spec.merge(ns: namespace, key: key) spec[:name] ||= key.to_a.join("_") database.command(createIndexes: collection_name, indexes: [spec]) end
each(&block)
click to toggle source
# File lib/patches/db_commands.rb, line 63 def each(&block) list_indexes_command.each(&block) end
Protected Instance Methods
list_indexes_command()
click to toggle source
# File lib/patches/db_commands.rb, line 69 def list_indexes_command database.command(listIndexes: collection_name)["cursor"]["firstBatch"] end
normalize_keys(spec)
click to toggle source
# File lib/patches/db_commands.rb, line 73 def normalize_keys(spec) return false if spec.is_a?(String) spec.reduce({}) do |transformed, (key, value)| transformed[key.to_s] = value transformed end end