Module: CZTop::Config::Traversing
- Included in:
- CZTop::Config
- Defined in:
- lib/cztop/config/traversing.rb
Overview
Methods used to traverse a CZTop::Config tree.
Defined Under Namespace
Classes: ChildrenAccessor, FamilyAccessor, SiblingsAccessor
Instance Method Summary collapse
-
#children ⇒ ChildrenAccessor
Access to this config item’s direct children.
-
#execute {|config, level| ... } ⇒ Object
Calls the given block once for each CZTop::Config item in the tree, starting with self.
-
#last_at_depth(level) ⇒ Config?
Finds last item at given level (0 = root).
-
#locate(path) ⇒ Config?
Finds a config item along a path, relative to the current item.
-
#siblings ⇒ SiblingsAccessor
Access to this config item’s siblings.
Instance Method Details
#children ⇒ ChildrenAccessor
Access to this config item’s direct children.
47 48 49 |
# File 'lib/cztop/config/traversing.rb', line 47 def children ChildrenAccessor.new(self) end |
#execute {|config, level| ... } ⇒ Object
Calls the given block once for each CZTop::Config item in the tree, starting with self.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cztop/config/traversing.rb', line 14 def execute raise ArgumentError, "no block given" unless block_given? exception = nil block_value = nil ret = nil callback = CZMQ::FFI::Zconfig.fct do |zconfig, _arg, level| begin # NOTE: work around JRuby and Rubinius bug, where it'd keep calling # this FFI::Function, even when the block `break`ed if ret != -1 config = from_ffi_delegate(zconfig) block_value = yield config, level ret = 0 # report success to keep zconfig_execute() going end rescue # remember exception, so we can raise it later to the ruby code # (it can't be raised now, as we have to report failure to # zconfig_execute()) exception = $! ret = -1 # report failure to stop zconfig_execute() immediately ensure ret ||= -1 # in case of 'break' end ret end ffi_delegate.execute(callback, _arg = nil) raise exception if exception return block_value end |
#last_at_depth(level) ⇒ Config?
Finds last item at given level (0 = root).
148 149 150 151 152 |
# File 'lib/cztop/config/traversing.rb', line 148 def last_at_depth(level) ptr = ffi_delegate.at_depth(level) return nil if ptr.null? from_ffi_delegate(ptr) end |
#locate(path) ⇒ Config?
Finds a config item along a path, relative to the current item.
139 140 141 142 143 |
# File 'lib/cztop/config/traversing.rb', line 139 def locate(path) ptr = ffi_delegate.locate(path) return nil if ptr.null? from_ffi_delegate(ptr) end |
#siblings ⇒ SiblingsAccessor
Note:
Only the “younger” (later in the ZPL file) config items are considered.
Access to this config item’s siblings.
55 56 57 |
# File 'lib/cztop/config/traversing.rb', line 55 def siblings SiblingsAccessor.new(self) end |