Module: CZTop::Config::Serialization

Included in:
CZTop::Config
Defined in:
lib/cztop/config/serialization.rb

Overview

Methods used around serialization of CZTop::Config items.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#_dump(_level) ⇒ String

Note:

This method is automatically used by Marshal.dump.

Serialize (marshal) this Config and all its children.

Returns:



74
75
76
# File 'lib/cztop/config/serialization.rb', line 74

def _dump(_level)
  to_s
end

#filenameString

Returns the path/filename of the file this CZTop::Config tree was loaded from.

Returns:

  • (String)


11
12
13
# File 'lib/cztop/config/serialization.rb', line 11

def filename
  ffi_delegate.filename
end

#reloadvoid

This method returns an undefined value.

Reload config tree from same file that it was previously loaded from.

Raises:

  • (TypeError)

    if this is an in-memory config

  • (SystemCallError)

    if this fails (no existing data will be changed)



59
60
61
62
63
64
65
66
67
68
# File 'lib/cztop/config/serialization.rb', line 59

def reload
  # NOTE: can't use Zconfig.reload, as we won't get the self pointer that
  # gets reassigned by zconfig_reload(). We can just use Zconfig.load and
  # swap out the FFI delegate.
  filename = filename() or
    raise TypeError, "can't reload in-memory config"
  ptr = CZMQ::FFI::Zconfig.load(filename)
  return attach_ffi_delegate(ptr) unless ptr.null?
  raise_zmq_err("error while reloading from the file %p" % filename)
end

#save(path) ⇒ void

This method returns an undefined value.

Saves the Config tree to a file.

Parameters:

  • path (String, Pathname, #to_s)

    the path to the ZPL config file

Raises:

  • (SystemCallError)

    if this fails



48
49
50
51
52
# File 'lib/cztop/config/serialization.rb', line 48

def save(path)
  rc = ffi_delegate.save(path.to_s)
  return if rc == 0
  raise_zmq_err("error while saving to the file %s" % path)
end

#to_sString

Serialize to a string in the ZPL format.

Returns:

  • (String)


5
6
7
# File 'lib/cztop/config/serialization.rb', line 5

def to_s
  ffi_delegate.str_save.read_string
end