Class: Pdns::Remotebackend::Connector
- Inherits:
-
Object
- Object
- Pdns::Remotebackend::Connector
- Defined in:
- lib/pdns/remotebackend.rb
Instance Method Summary collapse
-
#initialize(klass, options = {}) ⇒ Connector
constructor
A new instance of Connector.
-
#mainloop(reader, writer) ⇒ Object
Reads one line at a time from remotebackend, and calls approriate method.
Constructor Details
#initialize(klass, options = {}) ⇒ Connector
Returns a new instance of Connector.
140 141 142 143 |
# File 'lib/pdns/remotebackend.rb', line 140 def initialize(klass, = {}) @handler = klass @options = end |
Instance Method Details
#mainloop(reader, writer) ⇒ Object
Reads one line at a time from remotebackend, and calls approriate method
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/pdns/remotebackend.rb', line 149 def mainloop(reader,writer) h = @handler.new reader.each_line do |line| # expect json input = {} line = line.strip next if line.empty? begin input = JSON.parse(line) method = "do_#{input["method"].downcase}" args = input["parameters"] || {} h.result = false h.log = [] if h.respond_to?(method.to_sym) == false res = false else h.send(method,args) end writer.puts ({:result => h.result, :log => h.log}).to_json rescue JSON::ParserError writer.puts ({:result => false, :log => "Cannot parse input #{line}"}).to_json next end end end |