Skip to content

Commit 9fca9d8

Browse files
committed
Support aliases for index options.
1 parent 2ec77f4 commit 9fca9d8

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

2+
#### 0.2.4
3+
4+
* Support aliases for index options.
5+
26
#### 0.2.3
37

48
* Backport valid index options from Mongoid 6.

lib/patches/db_commands.rb

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,41 @@ def collection_names
2121
module Moped
2222
class Indexes
2323

24+
OPTIONS = {
25+
:background => :background,
26+
:bits => :bits,
27+
:bucket_size => :bucketSize,
28+
:default_language => :default_language,
29+
:expire_after => :expireAfterSeconds,
30+
:expire_after_seconds => :expireAfterSeconds,
31+
:key => :key,
32+
:language_override => :language_override,
33+
:max => :max,
34+
:min => :min,
35+
:name => :name,
36+
:partial_filter_expression => :partialFilterExpression,
37+
:sparse => :sparse,
38+
:sphere_version => :'2dsphereIndexVersion',
39+
:storage_engine => :storageEngine,
40+
:text_version => :textIndexVersion,
41+
:unique => :unique,
42+
:version => :v,
43+
:weights => :weights,
44+
:collation => :collation
45+
}.freeze
46+
2447
def [](key)
2548
list_indexes_command.detect do |index|
2649
(index['name'] == key) || (index['key'] == normalize_keys(key))
2750
end
2851
end
2952

3053
def create(key, options = {})
31-
spec = options.merge(ns: namespace, key: key)
54+
spec = options.reduce({}) do |transformed, (key, value)|
55+
transformed[OPTIONS[key.to_sym]] = value if OPTIONS[key.to_sym]
56+
transformed
57+
end
58+
spec = spec.merge(ns: namespace, key: key)
3259
spec[:name] ||= key.to_a.join("_")
3360
database.command(createIndexes: collection_name, indexes: [spec])
3461
end

lib/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module MongoidMonkey
2-
VERSION = '0.2.3'
2+
VERSION = '0.2.4'
33
end

0 commit comments

Comments
 (0)