Class: WebVac::Vac

Inherits:
Object
  • Object
show all
Defined in:
lib/webvac.rb

Overview

Stateless-ish client for venti. I completely punted on implementing a venti client, so it just calls the vac/unvac binaries. Does the job!

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cfg) ⇒ Vac

Takes an instance of Config.



75
76
77
# File 'lib/webvac.rb', line 75

def initialize cfg
	@config = cfg
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



72
73
74
# File 'lib/webvac.rb', line 72

def config
  @config
end

Instance Method Details

#load!(vac) ⇒ Object



102
103
104
# File 'lib/webvac.rb', line 102

def load! vac
	load_io(vac).read
end

#load_io(vac) ⇒ Object



92
93
94
95
96
97
98
99
100
# File 'lib/webvac.rb', line 92

def load_io vac
	unless /^vac:[a-f0-9]{40}$/.match(vac)
		raise ArgumentError, "#{vac.inspect} not a vac score?"
	end
	IO.popen(
		{'venti' => config.venti_server},
		["#{config.plan9bin}/unvac", '-c', vac]
	).tap { |io| Thread.new { Process.wait(io.pid) } }			
end

#save!(fn) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/webvac.rb', line 79

def save! fn
	contents = File.read(fn)
	pi, po = IO.pipe
	io = IO.popen(
		{'venti' => config.venti_server},
		["#{config.plan9bin}/vac", '-i', File.basename(fn)],
		in: pi
	).tap { |io| Thread.new { Process.wait(io.pid) } }
	po.write contents
	po.close
	io.read.chomp.sub(/^vac:/, '')
end