Class: Perpetuity::MongoDB::Index
- Inherits:
-
Object
- Object
- Perpetuity::MongoDB::Index
- Defined in:
- lib/perpetuity/mongodb/index.rb
Constant Summary collapse
- KEY_ORDERS =
{ 1 => :ascending, -1 => :descending }
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #activate! ⇒ Object
- #active? ⇒ Boolean
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
- #inactive? ⇒ Boolean
-
#initialize(klass, attribute, options = {}) ⇒ Index
constructor
A new instance of Index.
- #order ⇒ Object
- #unique? ⇒ Boolean
Constructor Details
#initialize(klass, attribute, options = {}) ⇒ Index
Returns a new instance of Index.
7 8 9 10 11 12 13 |
# File 'lib/perpetuity/mongodb/index.rb', line 7 def initialize klass, attribute, ={} @collection = klass @attribute = attribute @unique = .fetch(:unique) { false } @order = .fetch(:order) { :ascending } @activated = false end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
5 6 7 |
# File 'lib/perpetuity/mongodb/index.rb', line 5 def attribute @attribute end |
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
5 6 7 |
# File 'lib/perpetuity/mongodb/index.rb', line 5 def collection @collection end |
Instance Method Details
#==(other) ⇒ Object
35 36 37 |
# File 'lib/perpetuity/mongodb/index.rb', line 35 def == other hash == other.hash end |
#activate! ⇒ Object
23 24 25 |
# File 'lib/perpetuity/mongodb/index.rb', line 23 def activate! @activated = true end |
#active? ⇒ Boolean
15 16 17 |
# File 'lib/perpetuity/mongodb/index.rb', line 15 def active? @activated end |
#eql?(other) ⇒ Boolean
39 40 41 |
# File 'lib/perpetuity/mongodb/index.rb', line 39 def eql? other self == other end |
#hash ⇒ Object
43 44 45 |
# File 'lib/perpetuity/mongodb/index.rb', line 43 def hash "#{collection}/#{attribute}:#{unique?}:#{order}".hash end |
#inactive? ⇒ Boolean
19 20 21 |
# File 'lib/perpetuity/mongodb/index.rb', line 19 def inactive? !active? end |
#order ⇒ Object
31 32 33 |
# File 'lib/perpetuity/mongodb/index.rb', line 31 def order @order end |
#unique? ⇒ Boolean
27 28 29 |
# File 'lib/perpetuity/mongodb/index.rb', line 27 def unique? @unique end |