Class: CephRuby::RadosObjectEnumerator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ceph-ruby/rados_object_enumerator.rb

Overview

Enumerator for Ceph Rados Objects

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pool) ⇒ RadosObjectEnumerator

Returns a new instance of RadosObjectEnumerator.



13
14
15
16
17
18
# File 'lib/ceph-ruby/rados_object_enumerator.rb', line 13

def initialize(pool)
  self.pool = pool
  @page = 0

  open
end

Class Attribute Details

.limitObject

Returns the value of attribute limit.



7
8
9
# File 'lib/ceph-ruby/rados_object_enumerator.rb', line 7

def limit
  @limit
end

Instance Attribute Details

#handleObject (readonly)

Returns the value of attribute handle.



11
12
13
# File 'lib/ceph-ruby/rados_object_enumerator.rb', line 11

def handle
  @handle
end

#pageObject (readonly)

Returns the value of attribute page.



11
12
13
# File 'lib/ceph-ruby/rados_object_enumerator.rb', line 11

def page
  @page
end

#poolObject

Returns the value of attribute pool.



10
11
12
# File 'lib/ceph-ruby/rados_object_enumerator.rb', line 10

def pool
  @pool
end

Instance Method Details

#closeObject



37
38
39
40
# File 'lib/ceph-ruby/rados_object_enumerator.rb', line 37

def close
  Lib::Rados.rados_nobjects_close(handle)
  @handle = nil
end

#eachObject



55
56
57
58
59
60
61
62
63
64
# File 'lib/ceph-ruby/rados_object_enumerator.rb', line 55

def each
  return enum_for(:each) unless block_given?
  while within_limit
    obj = next_rados_object
    return if obj.nil?
    yield obj
  end
ensure
  paginate(page)
end

#openObject



46
47
48
49
50
51
52
53
# File 'lib/ceph-ruby/rados_object_enumerator.rb', line 46

def open
  return if open?
  pool.ensure_open
  handle_p = FFI::MemoryPointer.new(:pointer)
  ret = Lib::Rados.rados_nobjects_list_open(pool.handle, handle_p)
  raise SystemCallError('unable to open object list', -ret) if ret < 0
  @handle = handle_p.get_pointer(0)
end

#open?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/ceph-ruby/rados_object_enumerator.rb', line 42

def open?
  !handle.nil?
end

#paginate(page = 0) ⇒ Object



20
21
22
23
24
25
# File 'lib/ceph-ruby/rados_object_enumerator.rb', line 20

def paginate(page = 0)
  @page = page ||= 0
  to = CephRuby::RadosObjectEnumerator.limit
  to = 0 if to.nil?
  seek page * to
end

#positionObject



33
34
35
# File 'lib/ceph-ruby/rados_object_enumerator.rb', line 33

def position
  Lib::Rados.rados_nobjects_list_get_pg_hash_position(handle)
end

#seek(to) ⇒ Object



27
28
29
30
31
# File 'lib/ceph-ruby/rados_object_enumerator.rb', line 27

def seek(to)
  ret = Lib::Rados.rados_nobjects_list_seek(handle, to)
  raise SystemCallError('unable to seek to position', -ret) if ret < 0
  self
end

#within_limitObject



66
67
68
69
# File 'lib/ceph-ruby/rados_object_enumerator.rb', line 66

def within_limit
  return true if CephRuby::RadosObjectEnumerator.limit.nil?
  position < (CephRuby::RadosObjectEnumerator.limit * (page + 1))
end