Class: Async::Container::Notify::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/async/container/notify/server.rb

Defined Under Namespace

Classes: Context

Constant Summary collapse

NOTIFY_SOCKET =
'NOTIFY_SOCKET'
MAXIMUM_MESSAGE_SIZE =
4096

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Server

Returns a new instance of Server.



52
53
54
# File 'lib/async/container/notify/server.rb', line 52

def initialize(path)
	@path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



56
57
58
# File 'lib/async/container/notify/server.rb', line 56

def path
  @path
end

Class Method Details

.generate_pathObject



41
42
43
44
45
46
# File 'lib/async/container/notify/server.rb', line 41

def self.generate_path
	File.expand_path(
		"async-container-#{::Process.pid}-#{SecureRandom.hex(8)}.ipc",
		Dir.tmpdir
	)
end

.load(message) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/async/container/notify/server.rb', line 21

def self.load(message)
	lines = message.split("\n")
	
	lines.pop if lines.last == ""
	
	pairs = lines.map do |line|
		key, value = line.split("=", 2)
		
		if value == '0'
			value = false
		elsif value == '1'
			value = true
		end
		
		next [key.downcase.to_sym, value]
	end
	
	return Hash[pairs]
end

.open(path = self.generate_path) ⇒ Object



48
49
50
# File 'lib/async/container/notify/server.rb', line 48

def self.open(path = self.generate_path)
	self.new(path)
end

Instance Method Details

#bindObject



58
59
60
# File 'lib/async/container/notify/server.rb', line 58

def bind
	Context.new(@path)
end