Class: PostgresPR::Authentification

Inherits:
Message
  • Object
show all
Defined in:
lib/postgres-pr/message.rb

Constant Summary collapse

AuthTypeMap =
Hash.new { UnknownAuthType }

Constants inherited from Message

Message::MsgTypeMap

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Message

dump, fields, read, register_message_type

Class Method Details

.create(buffer) ⇒ Object



113
114
115
116
117
118
119
120
# File 'lib/postgres-pr/message.rb', line 113

def self.create(buffer)
  buffer.position = 5
  authtype = buffer.read_int32_network
  klass = AuthTypeMap[authtype]
  obj = klass.allocate
  obj.parse(buffer)
  obj
end

.register_auth_type(type) ⇒ Object

Raises:



122
123
124
125
126
127
# File 'lib/postgres-pr/message.rb', line 122

def self.register_auth_type(type)
  raise(PGError, "duplicate auth type registration") if AuthTypeMap.has_key?(type)
  AuthTypeMap[type] = self
  self.const_set(:AuthType, type) 
  class_eval "def auth_type() AuthType end"
end

Instance Method Details

#dumpObject



132
133
134
135
136
# File 'lib/postgres-pr/message.rb', line 132

def dump
  super(4) do |buffer|
    buffer.write_int32_network(self.auth_type)
  end
end

#message__dumpObject

the dump method of class Message



130
# File 'lib/postgres-pr/message.rb', line 130

alias message__dump dump

#parse(buffer) ⇒ Object



138
139
140
141
142
143
144
# File 'lib/postgres-pr/message.rb', line 138

def parse(buffer)
  super do
    auth_t = buffer.read_int32_network 
    raise ParseError unless auth_t == self.auth_type
    yield if block_given?
  end
end