Class: RemoteInfo
- Inherits:
-
Object
- Object
- RemoteInfo
- Defined in:
- lib/commons.rb
Constant Summary collapse
- FILENAME =
".reminfo"
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#netns ⇒ Object
Returns the value of attribute netns.
-
#operations ⇒ Object
Returns the value of attribute operations.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#path ⇒ Object
Returns the value of attribute path.
-
#port ⇒ Object
Returns the value of attribute port.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
- .filename(folder) ⇒ Object
- .load(folder = ".") ⇒ Object
- .lock_all(local, prevent_write = true) ⇒ Object
- .unlock_all(local) ⇒ Object
Instance Method Summary collapse
- #can_pull? ⇒ Boolean
- #can_push? ⇒ Boolean
-
#initialize ⇒ RemoteInfo
constructor
A new instance of RemoteInfo.
- #read_info(folder) ⇒ Object
- #save_info(to = ".") ⇒ Object
Constructor Details
#initialize ⇒ RemoteInfo
Returns a new instance of RemoteInfo.
20 21 22 23 24 25 26 27 28 |
# File 'lib/commons.rb', line 20 def initialize @netns = nil @owner = nil @port = nil @user = nil @operations = "rw" end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
12 13 14 |
# File 'lib/commons.rb', line 12 def host @host end |
#netns ⇒ Object
Returns the value of attribute netns.
16 17 18 |
# File 'lib/commons.rb', line 16 def netns @netns end |
#operations ⇒ Object
Returns the value of attribute operations.
18 19 20 |
# File 'lib/commons.rb', line 18 def operations @operations end |
#owner ⇒ Object
Returns the value of attribute owner.
17 18 19 |
# File 'lib/commons.rb', line 17 def owner @owner end |
#path ⇒ Object
Returns the value of attribute path.
15 16 17 |
# File 'lib/commons.rb', line 15 def path @path end |
#port ⇒ Object
Returns the value of attribute port.
13 14 15 |
# File 'lib/commons.rb', line 13 def port @port end |
#user ⇒ Object
Returns the value of attribute user.
14 15 16 |
# File 'lib/commons.rb', line 14 def user @user end |
Class Method Details
.filename(folder) ⇒ Object
36 37 38 |
# File 'lib/commons.rb', line 36 def self.filename(folder) return File.join(folder, FILENAME) end |
.load(folder = ".") ⇒ Object
30 31 32 33 34 |
# File 'lib/commons.rb', line 30 def self.load(folder=".") rinfo = RemoteInfo.new rinfo.read_info(folder) return rinfo end |
.lock_all(local, prevent_write = true) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/commons.rb', line 96 def self.lock_all(local, prevent_write=true) if (prevent_write) FS.each_remote_info(local) do |rinfo| OS.run "chmod -w \"#{rinfo}\"" end end yield if (prevent_write) FS.each_remote_info(local) do |rinfo| OS.run "chmod +w \"#{rinfo}\"" end end end |
.unlock_all(local) ⇒ Object
92 93 94 |
# File 'lib/commons.rb', line 92 def self.unlock_all(local) self.lock_all(local, true) {} end |
Instance Method Details
#can_pull? ⇒ Boolean
40 41 42 |
# File 'lib/commons.rb', line 40 def can_pull? return @operations.include? "r" end |
#can_push? ⇒ Boolean
44 45 46 |
# File 'lib/commons.rb', line 44 def can_push? return @operations.include? "w" end |
#read_info(folder) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/commons.rb', line 48 def read_info(folder) info = File.read(File.join(folder, FILENAME)) rows = info.split "\n" rows.each do |r| key, value = *r.split("\t") key = key.strip value = value.strip case key when "host" @host = value when "port" @port = value when "user" @user = value when "path" @path = value when "netns" @netns = value when "owner" @owner = value when "operations" @operations = value end end end |
#save_info(to = ".") ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/commons.rb', line 77 def save_info(to=".") content = "" content += "host\t#@host\n" content += "port\t#@port\n" if @port content += "user\t#@user\n" if @user content += "path\t#@path\n" content += "netns\t#@netns\n" if @netns content += "owner\t#@owner\n" if @owner content += "operations\t#@operations\n" dest = to ? File.join(to, FILENAME) : FILENAME File.write dest, content end |