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:



90
91
92
# File 'lib/cztop/config/serialization.rb', line 90

def _dump(_level)
  to_s
end

#filenameString

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

Returns:

  • (String)


15
16
17
# File 'lib/cztop/config/serialization.rb', line 15

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)



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/cztop/config/serialization.rb', line 73

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(format('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



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

def save(path)
  rc = ffi_delegate.save(path.to_s)
  return if rc.zero?

  raise_zmq_err(format('error while saving to the file %s', path))
end

#to_sString

Serialize to a string in the ZPL format.

Returns:

  • (String)


8
9
10
# File 'lib/cztop/config/serialization.rb', line 8

def to_s
  ffi_delegate.str_save.read_string
end