Class: RVC::FilesystemSession
- Inherits:
-
Object
- Object
- RVC::FilesystemSession
- Defined in:
- lib/rvc/filesystem_session.rb
Instance Method Summary collapse
- #connections ⇒ Object
- #get_connection(key) ⇒ Object
- #get_mark(key) ⇒ Object
-
#initialize(name) ⇒ FilesystemSession
constructor
A new instance of FilesystemSession.
- #marks ⇒ Object
- #set_connection(key, conn) ⇒ Object
- #set_mark(key, objs) ⇒ Object
Constructor Details
#initialize(name) ⇒ FilesystemSession
Returns a new instance of FilesystemSession.
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/rvc/filesystem_session.rb', line 4 def initialize name fail "invalid session name" unless name =~ /^[\w-]+$/ @dir = File.join(ENV['HOME'], '.rvc', 'sessions', name) prev_umask = File.umask 077 FileUtils.mkdir_p @dir FileUtils.mkdir_p mark_dir FileUtils.mkdir_p connection_dir File.umask prev_umask @priv = {} end |
Instance Method Details
#connections ⇒ Object
48 49 50 |
# File 'lib/rvc/filesystem_session.rb', line 48 def connections Dir.entries(connection_dir).reject { |x| x == '.' || x == '..' } end |
#get_connection(key) ⇒ Object
52 53 54 55 |
# File 'lib/rvc/filesystem_session.rb', line 52 def get_connection key return nil unless File.exists? connection_fn(key) File.open(connection_fn(key)) { |io| YAML.load io } end |
#get_mark(key) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rvc/filesystem_session.rb', line 19 def get_mark key if is_private_mark? key @priv[key] else return nil unless File.exists? mark_fn(key) File.readlines(mark_fn(key)). map { |path| RVC::Util.lookup(path.chomp) }. inject([], &:+) end end |
#marks ⇒ Object
15 16 17 |
# File 'lib/rvc/filesystem_session.rb', line 15 def marks Dir.entries(mark_dir).reject { |x| x == '.' || x == '..' } + @priv.keys end |
#set_connection(key, conn) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/rvc/filesystem_session.rb', line 57 def set_connection key, conn if conn == nil File.unlink(connection_fn(key)) else File.open(connection_fn(key), 'w') { |io| YAML.dump conn, io } end end |
#set_mark(key, objs) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rvc/filesystem_session.rb', line 30 def set_mark key, objs if is_private_mark? key if objs == nil @priv.delete key else @priv[key] = objs end else if objs == nil File.unlink mark_fn(key) else File.open(mark_fn(key), 'w') do |io| objs.each { |obj| io.puts obj.rvc_path_str } end end end end |