Class: Perpetuity::MongoDB::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/perpetuity/mongodb/index.rb

Constant Summary collapse

KEY_ORDERS =
{ 1 => :ascending, -1 => :descending }

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options={}
  @collection = klass
  @attribute = attribute
  @unique = options.fetch(:unique) { false }
  @order = options.fetch(:order) { :ascending }
  @activated = false
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



5
6
7
# File 'lib/perpetuity/mongodb/index.rb', line 5

def attribute
  @attribute
end

#collectionObject (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

Returns:

  • (Boolean)


15
16
17
# File 'lib/perpetuity/mongodb/index.rb', line 15

def active?
  @activated
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/perpetuity/mongodb/index.rb', line 39

def eql? other
  self == other
end

#hashObject



43
44
45
# File 'lib/perpetuity/mongodb/index.rb', line 43

def hash
  "#{collection}/#{attribute}:#{unique?}:#{order}".hash
end

#inactive?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/perpetuity/mongodb/index.rb', line 19

def inactive?
  !active?
end

#orderObject



31
32
33
# File 'lib/perpetuity/mongodb/index.rb', line 31

def order
  @order
end

#unique?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/perpetuity/mongodb/index.rb', line 27

def unique?
  @unique
end