Class: Mongoid::Indexable::Specification
- Inherits:
-
Object
- Object
- Mongoid::Indexable::Specification
- Defined in:
- lib/mongoid/indexable/specification.rb
Overview
Encapsulates behavior around an index specification.
Constant Summary collapse
- MAPPINGS =
The mappings of nice Ruby-style names to the corresponding driver option name.
{ expire_after_seconds: :expire_after }
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#key ⇒ Hash
The index key.
-
#klass ⇒ Class
The class the index is defined on.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#==(other) ⇒ true | false
Is this index specification equal to another?.
-
#initialize(klass, key, opts = nil) ⇒ Specification
constructor
Instantiate a new index specification.
-
#name ⇒ String
Get the index name, generated using the index key.
Constructor Details
#initialize(klass, key, opts = nil) ⇒ Specification
Instantiate a new index specification.
44 45 46 47 48 49 50 51 |
# File 'lib/mongoid/indexable/specification.rb', line 44 def initialize(klass, key, opts = nil) = opts || {} Validators::Options.validate(klass, key, ) @klass = klass @key = normalize_aliases!(key.dup) @fields = @key.keys @options = (.deep_dup) end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
22 23 24 |
# File 'lib/mongoid/indexable/specification.rb', line 22 def fields @fields end |
#key ⇒ Hash
Returns The index key.
22 |
# File 'lib/mongoid/indexable/specification.rb', line 22 attr_reader :klass, :key, :fields, :options |
#klass ⇒ Class
Returns The class the index is defined on.
22 23 24 |
# File 'lib/mongoid/indexable/specification.rb', line 22 def klass @klass end |
#options ⇒ Object
Returns the value of attribute options.
22 |
# File 'lib/mongoid/indexable/specification.rb', line 22 attr_reader :klass, :key, :fields, :options |
Instance Method Details
#==(other) ⇒ true | false
Is this index specification equal to another?
32 33 34 |
# File 'lib/mongoid/indexable/specification.rb', line 32 def ==(other) fields == other.fields && key == other.key end |
#name ⇒ String
Get the index name, generated using the index key.
59 60 61 62 63 |
# File 'lib/mongoid/indexable/specification.rb', line 59 def name @name ||= key.reduce([]) do |n, (k,v)| n << "#{k}_#{v}" end.join('_') end |