Class: CephRuby::RadosObjectEnumerator
- Inherits:
-
Object
- Object
- CephRuby::RadosObjectEnumerator
- Includes:
- Enumerable
- Defined in:
- lib/ceph-ruby/rados_object_enumerator.rb
Overview
Enumerator for Ceph Rados Objects
Class Attribute Summary collapse
-
.limit ⇒ Object
Returns the value of attribute limit.
Instance Attribute Summary collapse
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#pool ⇒ Object
Returns the value of attribute pool.
Instance Method Summary collapse
- #close ⇒ Object
- #each ⇒ Object
-
#initialize(pool) ⇒ RadosObjectEnumerator
constructor
A new instance of RadosObjectEnumerator.
- #open ⇒ Object
- #open? ⇒ Boolean
- #paginate(page = 0) ⇒ Object
- #position ⇒ Object
- #seek(to) ⇒ Object
- #within_limit ⇒ Object
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
.limit ⇒ Object
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
#handle ⇒ Object (readonly)
Returns the value of attribute handle.
11 12 13 |
# File 'lib/ceph-ruby/rados_object_enumerator.rb', line 11 def handle @handle end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
11 12 13 |
# File 'lib/ceph-ruby/rados_object_enumerator.rb', line 11 def page @page end |
#pool ⇒ Object
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
#close ⇒ Object
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 |
#each ⇒ Object
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 |
#open ⇒ Object
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
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 |
#position ⇒ Object
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_limit ⇒ Object
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 |