Module: Ohm::SortedMethods

Included in:
SortedSet
Defined in:
lib/ohm/sorted.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



7
8
9
# File 'lib/ohm/sorted.rb', line 7

def key
  @key
end

#modelObject (readonly)

Returns the value of attribute model.



9
10
11
# File 'lib/ohm/sorted.rb', line 9

def model
  @model
end

#namespaceObject (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 = @options.merge(range: range)
  SortedSet.new(key, namespace, model, opts)
end

#countObject



26
27
28
# File 'lib/ohm/sorted.rb', line 26

def count
  @options.fetch(:count, -1)
end

#idsObject



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, options={})
  @key = key
  @namespace = namespace
  @model = model
  @options = options
end

#offsetObject



22
23
24
# File 'lib/ohm/sorted.rb', line 22

def offset
  @options.fetch(:offset, 0)
end

#rangeObject



18
19
20
# File 'lib/ohm/sorted.rb', line 18

def range
  @options.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 = @options.merge(offset: offset, count: count)
    SortedSet.new(key, namespace, model, opts)
  else
    raise ArgumentError
  end
end