Class: Ohm::SortedSet

Inherits:
Model::Collection
  • Object
show all
Includes:
SortedMethods
Defined in:
lib/ohm/sorted.rb,
lib/ohm/sorted.rb

Direct Known Subclasses

RangedSortedSet

Instance Attribute Summary

Attributes included from SortedMethods

#key, #model, #namespace

Instance Method Summary collapse

Methods included from SortedMethods

#between, #count, #first, #ids, #initialize, #inspect, #offset, #reverse, #reversed?, #size, #slice

Instance Method Details

#[](id) ⇒ Object



116
117
118
# File 'lib/ohm/sorted.rb', line 116

def [](id)
  model[id] if !!db.zrank(key, id)
end

#allObject



124
125
126
# File 'lib/ohm/sorted.rb', line 124

def all
  ids.map(&model)
end

#dbObject



96
97
98
# File 'lib/ohm/sorted.rb', line 96

def db
  model.db
end

#eachObject



108
109
110
111
112
113
114
# File 'lib/ohm/sorted.rb', line 108

def each
  if block_given?
    ids.each { |id| block.call(model.to_proc[id]) }
  else
    to_enum(:each)
  end
end

#empty?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/ohm/sorted.rb', line 120

def empty?
  size == 0
end

#include?(model) ⇒ Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/ohm/sorted.rb', line 128

def include?(model)
  !!db.zrank(key, model.id)
end