Module: ZK::Client::Unixisms
- Included in:
- Base
- Defined in:
- lib/z_k/client/unixisms.rb
Instance Method Summary collapse
-
#find(*paths, &block) ⇒ Object
see ZK::Find for explanation.
-
#mkdir_p(path) ⇒ Object
Creates all parent paths and ‘path’ in zookeeper as persistent nodes with zero data.
-
#rm_rf(paths) ⇒ Object
recursively remove all children of path then remove path itself.
Instance Method Details
#find(*paths, &block) ⇒ Object
see ZK::Find for explanation
51 52 53 |
# File 'lib/z_k/client/unixisms.rb', line 51 def find(*paths, &block) ZK::Find.find(self, *paths, &block) end |
#mkdir_p(path) ⇒ Object
Creates all parent paths and ‘path’ in zookeeper as persistent nodes with zero data.
Arguments
-
path
: An absolute znode path to create
Examples
zk.exists?('/path')
# => false
zk.mkdir_p('/path/to/blah')
# => "/path/to/blah"
– TODO: write a non-recursive version of this. ruby doesn’t have TCO, so this could get expensive w/ psychotically long paths
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/z_k/client/unixisms.rb', line 21 def mkdir_p(path) create(path, '', :mode => :persistent) rescue Exceptions::NodeExists return rescue Exceptions::NoNode if File.dirname(path) == '/' # ok, we're screwed, blow up raise KeeperException, "could not create '/', something is wrong", caller end mkdir_p(File.dirname(path)) retry end |
#rm_rf(paths) ⇒ Object
recursively remove all children of path then remove path itself
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/z_k/client/unixisms.rb', line 36 def rm_rf(paths) Array(paths).flatten.each do |path| begin children(path).each do |child| rm_rf(File.join(path, child)) end delete(path) nil rescue Exceptions::NoNode end end end |