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.



68
69
70
# File 'lib/async/container/notify/server.rb', line 68

def initialize(path)
	@path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



72
73
74
# File 'lib/async/container/notify/server.rb', line 72

def path
  @path
end

Class Method Details

.generate_pathObject



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

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

.load(message) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/async/container/notify/server.rb', line 37

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



64
65
66
# File 'lib/async/container/notify/server.rb', line 64

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

Instance Method Details

#bindObject



74
75
76
# File 'lib/async/container/notify/server.rb', line 74

def bind
	Context.new(@path)
end