module CZTop::Config::Traversing

Methods used to traverse a {CZTop::Config} tree.

Public Instance Methods

children() click to toggle source

Access to this config item's direct children. @return [ChildrenAccessor]

# File lib/cztop/config/traversing.rb, line 47
def children
  ChildrenAccessor.new(self)
end
execute() { |config, level| ... } click to toggle source

Calls the given block once for each {Config} item in the tree, starting with self.

@yieldparam config [Config] the config item @yieldparam level [Integer] level of the item (self has level 0,

its direct children have level 1)

@return [Object] the block's return value @raise [ArgumentError] if no block given @raise [Exception] the block's exception, in case it raises (it won't

call the block any more after that)
# 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) click to toggle source

Finds last item at given level (0 = root). @return [Config] the last config item at given level @return [nil] if there's no config item at given level

# 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) click to toggle source

Finds a config item along a path, relative to the current item. @param path [String] path (leading slash is optional and will be

ignored)

@return [Config] the found config item @return [nil] if there's no config item under this path

# 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() click to toggle source

Access to this config item's siblings. @note Only the “younger” (later in the ZPL file) config items are

considered.

@return [SiblingsAccessor]

# File lib/cztop/config/traversing.rb, line 55
def siblings
  SiblingsAccessor.new(self)
end