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.
52 53 54 |
# File 'lib/cztop/config/traversing.rb', line 52 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.
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 44 45 46 47 |
# File 'lib/cztop/config/traversing.rb', line 16 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 StandardError # 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 = $ERROR_INFO 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 block_value end |
#last_at_depth(level) ⇒ Config?
Finds last item at given level (0 = root).
174 175 176 177 178 179 |
# File 'lib/cztop/config/traversing.rb', line 174 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.
163 164 165 166 167 168 |
# File 'lib/cztop/config/traversing.rb', line 163 def locate(path) ptr = ffi_delegate.locate(path) return nil if ptr.null? from_ffi_delegate(ptr) end |
#siblings ⇒ SiblingsAccessor
Only the “younger” (later in the ZPL file) config items are considered.
Access to this config item’s siblings.
61 62 63 |
# File 'lib/cztop/config/traversing.rb', line 61 def siblings SiblingsAccessor.new(self) end |