Module: Ohm::SortedMethods
- Included in:
- SortedSet
- Defined in:
- lib/ohm/sorted.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Instance Method Summary collapse
- #between(first, last) ⇒ Object
- #count ⇒ Object
- #ids ⇒ Object
- #initialize(key, namespace, model, options = {}) ⇒ Object
- #offset ⇒ Object
- #range ⇒ Object
- #slice(*args) ⇒ Object
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/ohm/sorted.rb', line 7 def key @key end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
9 10 11 |
# File 'lib/ohm/sorted.rb', line 9 def model @model end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
8 9 10 |
# File 'lib/ohm/sorted.rb', line 8 def namespace @namespace end |
Instance Method Details
#between(first, last) ⇒ Object
30 31 32 33 34 |
# File 'lib/ohm/sorted.rb', line 30 def between(first, last) range = first.to_f..last.to_f opts = .merge(range: range) SortedSet.new(key, namespace, model, opts) end |
#count ⇒ Object
26 27 28 |
# File 'lib/ohm/sorted.rb', line 26 def count .fetch(:count, -1) end |
#ids ⇒ Object
48 49 50 51 52 53 |
# File 'lib/ohm/sorted.rb', line 48 def ids execute do |key| db.zrangebyscore(key, range.begin, range.end, limit: [offset, count]) end end |
#initialize(key, namespace, model, options = {}) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/ohm/sorted.rb', line 11 def initialize(key, namespace, model, ={}) @key = key @namespace = namespace @model = model = end |
#offset ⇒ Object
22 23 24 |
# File 'lib/ohm/sorted.rb', line 22 def offset .fetch(:offset, 0) end |
#range ⇒ Object
18 19 20 |
# File 'lib/ohm/sorted.rb', line 18 def range .fetch(:range, "-inf".."inf") end |
#slice(*args) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ohm/sorted.rb', line 36 def slice(*args) if args.count == 1 self[args.first] elsif args.count == 2 offset, count = *args opts = .merge(offset: offset, count: count) SortedSet.new(key, namespace, model, opts) else raise ArgumentError end end |