Class: CZMQ::FFI::Zdir
- Inherits:
-
Object
- Object
- CZMQ::FFI::Zdir
- Defined in:
- lib/czmq-ffi-gen/czmq/ffi/zdir.rb
Overview
This class is 100% generated using zproject.
work with file-system directories
Defined Under Namespace
Classes: DestroyedError
Class Method Summary collapse
- .__new ⇒ Object
- .create_finalizer_for(ptr) ⇒ Proc
-
.diff(older, newer, alias_) ⇒ Zlist
Calculate differences between two versions of a directory tree.
-
.new(path, parent) ⇒ CZMQ::Zdir
Create a new directory item that loads in the full tree of the specified path, optionally located under some parent path.
-
.test(verbose) ⇒ void
Self test of this class.
-
.watch(pipe, unused) ⇒ void
Create a new zdir_watch actor instance:.
Instance Method Summary collapse
-
#__ptr ⇒ ::FFI::Pointer
(also: #to_ptr)
Return internal pointer.
-
#__ptr_give_ref ⇒ ::FFI::MemoryPointer
Nullify internal pointer and return pointer pointer.
-
#__undef_finalizer ⇒ void
Undefines the finalizer for this object.
-
#cache ⇒ Zhash
Load directory cache; returns a hash table containing the SHA-1 digests of every file in the tree.
-
#count ⇒ Integer
Return directory count.
-
#cursize ⇒ ::FFI::Pointer
Return total hierarchy size, in bytes of data contained in all files in the directory tree.
-
#destroy ⇒ void
Destroy a directory tree and all children it contains.
-
#fprint(file, indent) ⇒ void
Print contents of directory to open stream.
-
#initialize(ptr, finalize = true) ⇒ Zdir
constructor
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
-
#list ⇒ Zlist
Returns a sorted list of zfile objects; Each entry in the list is a pointer to a zfile_t item already allocated in the zdir tree.
-
#list_paths ⇒ Zlist
Returns a sorted list of char*; Each entry in the list is a path of a file or directory contained in self.
-
#modified ⇒ ::FFI::Pointer
Return last modification time for directory.
- #null? ⇒ Boolean
-
#path ⇒ String
Return directory path.
-
#print(indent) ⇒ void
Print contents of directory to stdout.
-
#remove(force) ⇒ void
Remove directory, optionally including all files that it contains, at all levels.
-
#resync(alias_) ⇒ Zlist
Return full contents of directory as a zdir_patch list.
Constructor Details
#initialize(ptr, finalize = true) ⇒ Zdir
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
24 25 26 27 28 29 30 31 32 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 24 def initialize(ptr, finalize = true) @ptr = ptr if @ptr.null? @ptr = nil # Remove null pointers so we don't have to test for them. elsif finalize @finalizer = self.class.create_finalizer_for @ptr ObjectSpace.define_finalizer self, @finalizer end end |
Class Method Details
.__new ⇒ Object
18 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 18 alias :__new :new |
.create_finalizer_for(ptr) ⇒ Proc
35 36 37 38 39 40 41 42 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 35 def self.create_finalizer_for(ptr) ptr_ptr = ::FFI::MemoryPointer.new :pointer Proc.new do ptr_ptr.write_pointer ptr ::CZMQ::FFI.zdir_destroy ptr_ptr end end |
.diff(older, newer, alias_) ⇒ Zlist
Calculate differences between two versions of a directory tree. Returns a list of zdir_patch_t patches. Either older or newer may be null, indicating the directory is empty/absent. If alias is set, generates virtual filename (minus path, plus alias).
187 188 189 190 191 192 193 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 187 def self.diff(older, newer, alias_) older = older.__ptr if older newer = newer.__ptr if newer result = ::CZMQ::FFI.zdir_diff(older, newer, alias_) result = Zlist.__new result, true result end |
.new(path, parent) ⇒ CZMQ::Zdir
Create a new directory item that loads in the full tree of the specified path, optionally located under some parent path. If parent is “-”, then loads only the top-level directory, and does not use parent as a path.
83 84 85 86 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 83 def self.new(path, parent) ptr = ::CZMQ::FFI.zdir_new(path, parent) __new ptr end |
.test(verbose) ⇒ void
This method returns an undefined value.
Self test of this class.
284 285 286 287 288 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 284 def self.test(verbose) verbose = !(0==verbose||!verbose) # boolean result = ::CZMQ::FFI.zdir_test(verbose) result end |
.watch(pipe, unused) ⇒ void
This method returns an undefined value.
Create a new zdir_watch actor instance:
zactor_t *watch = zactor_new (zdir_watch, NULL);
Destroy zdir_watch instance:
zactor_destroy (&watch);
Enable verbose logging of commands and activity:
zstr_send (watch, "VERBOSE");
Subscribe to changes to a directory path:
zsock_send (watch, "ss", "SUBSCRIBE", "directory_path");
Unsubscribe from changes to a directory path:
zsock_send (watch, "ss", "UNSUBSCRIBE", "directory_path");
Receive directory changes:
zsock_recv (watch, "sp", &path, &patches);
// Delete the received data.
free (path);
zlist_destroy (&patches);
274 275 276 277 278 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 274 def self.watch(pipe, unused) pipe = pipe.__ptr if pipe result = ::CZMQ::FFI.zdir_watch(pipe, unused) result end |
Instance Method Details
#__ptr ⇒ ::FFI::Pointer Also known as: to_ptr
Return internal pointer
49 50 51 52 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 49 def __ptr raise DestroyedError unless @ptr @ptr end |
#__ptr_give_ref ⇒ ::FFI::MemoryPointer
This detaches the current instance from the native object and thus makes it unusable.
Nullify internal pointer and return pointer pointer.
60 61 62 63 64 65 66 67 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 60 def __ptr_give_ref raise DestroyedError unless @ptr ptr_ptr = ::FFI::MemoryPointer.new :pointer ptr_ptr.write_pointer @ptr __undef_finalizer if @finalizer @ptr = nil ptr_ptr end |
#__undef_finalizer ⇒ void
Only use this if you need to and can guarantee that the native object will be freed by other means.
This method returns an undefined value.
Undefines the finalizer for this object.
72 73 74 75 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 72 def __undef_finalizer ObjectSpace.undefine_finalizer self @finalizer = nil end |
#cache ⇒ Zhash
Load directory cache; returns a hash table containing the SHA-1 digests of every file in the tree. The cache is saved between runs in .cache.
211 212 213 214 215 216 217 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 211 def cache() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zdir_cache(self_p) result = Zhash.__new result, true result end |
#count ⇒ Integer
Return directory count
132 133 134 135 136 137 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 132 def count() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zdir_count(self_p) result end |
#cursize ⇒ ::FFI::Pointer
Return total hierarchy size, in bytes of data contained in all files in the directory tree.
122 123 124 125 126 127 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 122 def cursize() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zdir_cursize(self_p) result end |
#destroy ⇒ void
This method returns an undefined value.
Destroy a directory tree and all children it contains.
91 92 93 94 95 96 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 91 def destroy() return unless @ptr self_p = __ptr_give_ref result = ::CZMQ::FFI.zdir_destroy(self_p) result end |
#fprint(file, indent) ⇒ void
This method returns an undefined value.
Print contents of directory to open stream
224 225 226 227 228 229 230 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 224 def fprint(file, indent) raise DestroyedError unless @ptr self_p = @ptr indent = Integer(indent) result = ::CZMQ::FFI.zdir_fprint(self_p, file, indent) result end |
#list ⇒ Zlist
Returns a sorted list of zfile objects; Each entry in the list is a pointer to a zfile_t item already allocated in the zdir tree. Do not destroy the original zdir tree until you are done with this list.
144 145 146 147 148 149 150 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 144 def list() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zdir_list(self_p) result = Zlist.__new result, true result end |
#list_paths ⇒ Zlist
Returns a sorted list of char*; Each entry in the list is a path of a file or directory contained in self.
156 157 158 159 160 161 162 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 156 def list_paths() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zdir_list_paths(self_p) result = Zlist.__new result, true result end |
#modified ⇒ ::FFI::Pointer
Return last modification time for directory.
111 112 113 114 115 116 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 111 def modified() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zdir_modified(self_p) result end |
#null? ⇒ Boolean
44 45 46 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 44 def null? !@ptr or @ptr.null? end |
#path ⇒ String
Return directory path
101 102 103 104 105 106 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 101 def path() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zdir_path(self_p) result end |
#print(indent) ⇒ void
This method returns an undefined value.
Print contents of directory to stdout
236 237 238 239 240 241 242 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 236 def print(indent) raise DestroyedError unless @ptr self_p = @ptr indent = Integer(indent) result = ::CZMQ::FFI.zdir_print(self_p, indent) result end |
#remove(force) ⇒ void
This method returns an undefined value.
Remove directory, optionally including all files that it contains, at all levels. If force is false, will only remove the directory if empty. If force is true, will remove all files and all subdirectories.
170 171 172 173 174 175 176 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 170 def remove(force) raise DestroyedError unless @ptr self_p = @ptr force = !(0==force||!force) # boolean result = ::CZMQ::FFI.zdir_remove(self_p, force) result end |
#resync(alias_) ⇒ Zlist
Return full contents of directory as a zdir_patch list.
199 200 201 202 203 204 205 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdir.rb', line 199 def resync(alias_) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zdir_resync(self_p, alias_) result = Zlist.__new result, true result end |