Class: Relix::PrimaryKeyIndex
- Inherits:
-
Index
- Object
- Index
- Relix::PrimaryKeyIndex
show all
- Includes:
- Ordering
- Defined in:
- lib/relix/indexes/primary_key.rb
Instance Attribute Summary
Attributes inherited from Index
#model_name
Instance Method Summary
collapse
-
#all(r, options = {}) ⇒ Object
-
#deindex(r, pk, old_value) ⇒ Object
-
#eq(r, value, options) ⇒ Object
-
#filter(r, object, value) ⇒ Object
-
#index(r, pk, object, value, old_value, rank) ⇒ Object
-
#initialize(set, base_name, accessor, options = {}) ⇒ PrimaryKeyIndex
constructor
A new instance of PrimaryKeyIndex.
-
#position(r, pk, value) ⇒ Object
-
#query(r, value) ⇒ Object
-
#watch_keys(*values) ⇒ Object
Methods inherited from Index
#attribute_immutable?, compact_kind, #create_query_clause, kind, #name, #normalize, #read, #read_normalized, #watch
Constructor Details
#initialize(set, base_name, accessor, options = {}) ⇒ PrimaryKeyIndex
Returns a new instance of PrimaryKeyIndex.
5
6
7
8
|
# File 'lib/relix/indexes/primary_key.rb', line 5
def initialize(set, base_name, accessor, options={})
options[:immutable_attribute] = true unless options.has_key?(:immutable_attribute)
super
end
|
Instance Method Details
#all(r, options = {}) ⇒ Object
30
31
32
|
# File 'lib/relix/indexes/primary_key.rb', line 30
def all(r, options={})
r.zrange(name, *range_from_options(r, options))
end
|
#deindex(r, pk, old_value) ⇒ Object
26
27
28
|
# File 'lib/relix/indexes/primary_key.rb', line 26
def deindex(r, pk, old_value)
r.zrem(name, pk)
end
|
#eq(r, value, options) ⇒ Object
34
35
36
|
# File 'lib/relix/indexes/primary_key.rb', line 34
def eq(r, value, options)
[value]
end
|
#filter(r, object, value) ⇒ Object
14
15
16
|
# File 'lib/relix/indexes/primary_key.rb', line 14
def filter(r, object, value)
!r.zscore(name, value)
end
|
#index(r, pk, object, value, old_value, rank) ⇒ Object
22
23
24
|
# File 'lib/relix/indexes/primary_key.rb', line 22
def index(r, pk, object, value, old_value, rank)
r.zadd(name, rank, pk)
end
|
#position(r, pk, value) ⇒ Object
38
39
40
41
42
|
# File 'lib/relix/indexes/primary_key.rb', line 38
def position(r, pk, value)
position = r.zrank(name, pk)
raise MissingIndexValueError, "Cannot find key #{pk} in index" unless position
position
end
|
#query(r, value) ⇒ Object
18
19
20
|
# File 'lib/relix/indexes/primary_key.rb', line 18
def query(r, value)
r.zcard(name)
end
|
#watch_keys(*values) ⇒ Object
10
11
12
|
# File 'lib/relix/indexes/primary_key.rb', line 10
def watch_keys(*values)
name
end
|