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
-
#_dump(_level) ⇒ String
Serialize (marshal) this Config and all its children.
-
#filename ⇒ String
Returns the path/filename of the file this CZTop::Config tree was loaded from.
-
#reload ⇒ void
Reload config tree from same file that it was previously loaded from.
-
#save(path) ⇒ void
Saves the Config tree to a file.
-
#to_s ⇒ String
Serialize to a string in the ZPL format.
Instance Method Details
#_dump(_level) ⇒ String
This method is automatically used by Marshal.dump.
Serialize (marshal) this Config and all its children.
90 91 92 |
# File 'lib/cztop/config/serialization.rb', line 90 def _dump(_level) to_s end |
#filename ⇒ String
Returns the path/filename of the file this CZTop::Config tree was loaded from.
15 16 17 |
# File 'lib/cztop/config/serialization.rb', line 15 def filename ffi_delegate.filename end |
#reload ⇒ void
This method returns an undefined value.
Reload config tree from same file that it was previously loaded from.
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.
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_s ⇒ String
Serialize to a string in the ZPL format.
8 9 10 |
# File 'lib/cztop/config/serialization.rb', line 8 def to_s ffi_delegate.str_save.read_string end |