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



113
114
115
# File 'lib/ohm/sorted.rb', line 113

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

#allObject



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

def all
  ids.map(&model)
end

#dbObject



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

def db
  model.db
end

#each(&block) ⇒ Object



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

def each(&block)
  return to_enum(:each) unless block
  ids.each { |id| block.call(model.to_proc[id]) }
end

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  size == 0
end

#include?(model) ⇒ Boolean

Returns:

  • (Boolean)


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

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