Class: DRbFileServer
- Inherits:
-
Object
- Object
- DRbFileServer
- Defined in:
- lib/drb_fileserver_plus.rb
Instance Attribute Summary collapse
-
#nodes ⇒ Object
Returns the value of attribute nodes.
Instance Method Summary collapse
- #chmod(permissions, fname) ⇒ Object
- #cp(path, path2) ⇒ Object
- #directory?(fname) ⇒ Boolean
- #exists?(fname) ⇒ Boolean
-
#initialize(nodes, sps: nil, topic: 'file') ⇒ DRbFileServer
constructor
A new instance of DRbFileServer.
- #ls(path) ⇒ Object
- #mkdir(path) ⇒ Object
- #mkdir_p(path) ⇒ Object
- #mv(path, path2) ⇒ Object
- #read(fname) ⇒ Object
- #rm(fname) ⇒ Object
- #write(fname, content) ⇒ Object
- #zip(fname, a) ⇒ Object
Constructor Details
#initialize(nodes, sps: nil, topic: 'file') ⇒ DRbFileServer
Returns a new instance of DRbFileServer.
16 17 18 19 20 21 22 |
# File 'lib/drb_fileserver_plus.rb', line 16 def initialize(nodes, sps: nil, topic: 'file') @nodes = nodes @failcount = 0 @sps, @topic = sps, topic end |
Instance Attribute Details
#nodes ⇒ Object
Returns the value of attribute nodes.
14 15 16 |
# File 'lib/drb_fileserver_plus.rb', line 14 def nodes @nodes end |
Instance Method Details
#chmod(permissions, fname) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/drb_fileserver_plus.rb', line 24 def chmod(, fname) node = '' file_op do |f| node = 'dfs://' + @nodes.first f.chmod , File.join(node, fname) end if @sps then @sps.notice "%s/chmod: %d %s" % [@topic, , File.join(node, fname)] end end |
#cp(path, path2) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/drb_fileserver_plus.rb', line 41 def cp(path, path2) node = '' file_op do |f| node = 'dfs://' + @nodes.first f.cp File.join(node, path), File.join(node, path2) end if @sps then @sps.notice "%s/copy: %s %s" % [@topic, File.join(node, path), File.join(node, path2)] end end |
#directory?(fname) ⇒ Boolean
57 58 59 60 61 62 63 64 |
# File 'lib/drb_fileserver_plus.rb', line 57 def directory?(fname) file_op do |f| node = 'dfs://' + @nodes.first f.directory? File.join(node, fname) end end |
#exists?(fname) ⇒ Boolean
66 67 68 69 70 71 72 73 |
# File 'lib/drb_fileserver_plus.rb', line 66 def exists?(fname) file_op do |f| node = 'dfs://' + @nodes.first f.exists? File.join(node, fname) end end |
#ls(path) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/drb_fileserver_plus.rb', line 75 def ls(path) file_op do |f| node = 'dfs://' + @nodes.first f.ls File.join(node, path) end end |
#mkdir(path) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/drb_fileserver_plus.rb', line 84 def mkdir(path) node = '' file_op do |f| node = 'dfs://' + @nodes.first f.mkdir File.join(node, path) end if @sps then @sps.notice "%s/mkdir: %s" % [@topic, File.join(node, path)] end end |
#mkdir_p(path) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/drb_fileserver_plus.rb', line 99 def mkdir_p(path) node = '' file_op do |f| node = 'dfs://' + @nodes.first f.mkdir_p File.join(node, path) end if @sps then @sps.notice "%s/mkdir_p: %s" % [@topic, File.join(node, path)] end end |
#mv(path, path2) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/drb_fileserver_plus.rb', line 114 def mv(path, path2) node = '' file_op do |f| node = 'dfs://' + @nodes.first f.mv File.join(node, path), File.join(node, path2) end if @sps then @sps.notice "%s/mv: %s %s" % [@topic, File.join(node, path), File.join(node, path2)] end end |
#read(fname) ⇒ Object
130 131 132 133 134 135 136 137 |
# File 'lib/drb_fileserver_plus.rb', line 130 def read(fname) file_op do |f| node = 'dfs://' + @nodes.first f.read File.join(node, fname) end end |
#rm(fname) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/drb_fileserver_plus.rb', line 139 def rm(fname) node = '' file_op do |f| node = 'dfs://' + @nodes.first f.rm File.join(node, fname) end if @sps then @sps.notice "%s/rm: %s" % [@topic, File.join(node, fname)] end end |
#write(fname, content) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/drb_fileserver_plus.rb', line 154 def write(fname, content) node = '' file_op do |f| node = 'dfs://' + @nodes.first f.write File.join(node, fname), content end if @sps then @sps.notice("%s/write: %s" % [@topic, File.join(node, fname)]) end end |
#zip(fname, a) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/drb_fileserver_plus.rb', line 169 def zip(fname, a) node = '' file_op do |f| node = 'dfs://' + @nodes.first f.zip File.join(node, fname), a end if @sps then @sps.notice "%s/zip: %s" % [@topic, File.join(node, fname)] end end |