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.



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

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Class Method Details

.generate_pathObject



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

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

.load(message) ⇒ Object



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

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



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

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

Instance Method Details

#bindObject



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

def bind
  Context.new(@path)
end