Class: Ohm::SortedSet
- Inherits:
-
Model::Collection
- Object
- Model::Collection
- Ohm::SortedSet
show all
- Includes:
- SortedMethods
- Defined in:
- lib/ohm/sorted.rb,
lib/ohm/sorted.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#between, #count, #ids, #offset, #range, #slice
Constructor Details
#initialize(key, namespace, model, options = {}) ⇒ SortedSet
Returns a new instance of SortedSet.
89
90
91
92
93
94
|
# File 'lib/ohm/sorted.rb', line 89
def initialize(key, namespace, model, options={})
@key = key
@model = model
@namespace = namespace
@options = options
end
|
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
85
86
87
|
# File 'lib/ohm/sorted.rb', line 85
def key
@key
end
|
#model ⇒ Object
Returns the value of attribute model.
87
88
89
|
# File 'lib/ohm/sorted.rb', line 87
def model
@model
end
|
#namespace ⇒ Object
Returns the value of attribute namespace.
86
87
88
|
# File 'lib/ohm/sorted.rb', line 86
def namespace
@namespace
end
|
Instance Method Details
#[](id) ⇒ Object
104
105
106
|
# File 'lib/ohm/sorted.rb', line 104
def [](id)
model[id] if !!db.zrank(key, id)
end
|
#all ⇒ Object
116
117
118
|
# File 'lib/ohm/sorted.rb', line 116
def all
ids.map(&model)
end
|
#db ⇒ Object
77
78
79
|
# File 'lib/ohm/sorted.rb', line 77
def db
model.db
end
|
#each(&block) ⇒ Object
100
101
102
|
# File 'lib/ohm/sorted.rb', line 100
def each(&block)
ids.each { |id| block.call(model.to_proc[id]) }
end
|
#empty? ⇒ Boolean
112
113
114
|
# File 'lib/ohm/sorted.rb', line 112
def empty?
size == 0
end
|
#first ⇒ Object
64
65
66
|
# File 'lib/ohm/sorted.rb', line 64
def first
fetch(execute { |key| db.zrange(key, 0, 1) }).first
end
|
#include?(model) ⇒ Boolean
125
126
127
|
# File 'lib/ohm/sorted.rb', line 125
def include?(model)
!!db.zrank(key, model.id)
end
|
#inspect ⇒ Object
129
130
131
|
# File 'lib/ohm/sorted.rb', line 129
def inspect
"#<SortedSet (#{model}): #{db.zrange(key, 0, -1).inspect}>"
end
|
#size ⇒ Object
60
61
62
|
# File 'lib/ohm/sorted.rb', line 60
def size
execute { |key| db.zcard(key) }
end
|