Class: Mongoid::Indexable::Specification
- Inherits:
-
Object
- Object
- Mongoid::Indexable::Specification
- Defined in:
- lib/mongoid/indexable/specification.rb
Overview
Encapsulates behaviour around an index specification.
Constant Summary collapse
- MAPPINGS =
The mappings of nice Ruby-style names to the corresponding MongoDB name.
{ bucket_size: :bucketSize, drop_dups: :dropDups, expire_after_seconds: :expireAfterSeconds }
Instance Attribute Summary collapse
-
#key ⇒ Hash
The index key.
-
#klass ⇒ Class
The class the index is defined on.
- #options ⇒ Object
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Is this index specification equal to another?.
-
#fields ⇒ Array<Symbol>
Get an array of the fields, in order, that are part of the index.
-
#initialize(klass, key, opts = nil) ⇒ Specification
constructor
Instantiate a new index specification.
Constructor Details
#initialize(klass, key, opts = nil) ⇒ Specification
Instantiate a new index specification.
64 65 66 67 68 69 70 |
# File 'lib/mongoid/indexable/specification.rb', line 64 def initialize(klass, key, opts = nil) = opts || {} Validators::Options.validate(klass, key, ) @klass = klass @key = normalize_key(key) @options = (.dup) end |
Instance Attribute Details
#key ⇒ Hash
Returns The index key.
26 |
# File 'lib/mongoid/indexable/specification.rb', line 26 attr_reader :klass, :key, :options |
#klass ⇒ Class
Returns The class the index is defined on.
26 27 28 |
# File 'lib/mongoid/indexable/specification.rb', line 26 def klass @klass end |
#options ⇒ Object
26 |
# File 'lib/mongoid/indexable/specification.rb', line 26 attr_reader :klass, :key, :options |
Instance Method Details
#==(other) ⇒ true, false
Is this index specification equal to another?
38 39 40 |
# File 'lib/mongoid/indexable/specification.rb', line 38 def ==(other) fields == other.fields end |
#fields ⇒ Array<Symbol>
Get an array of the fields, in order, that are part of the index.
50 51 52 |
# File 'lib/mongoid/indexable/specification.rb', line 50 def fields key.keys end |