summaryrefslogtreecommitdiff
path: root/lib/nickserver/lookup.rb
blob: 105e77e13a182090bf35b9cd323687d1dc88185c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'nickserver/invalid_source'

module Nickserver
  class Lookup

    attr_reader :nick

    def initialize(nick)
      @nick = nick
    end

    def respond_with(responder)
      query do |status, content|
        responder.send_response status: status, content: content
      end
    end

    protected

    def query(&block)
      source.query nick, &block
    end

    def source
      if nick.invalid?  then Nickserver::InvalidSource
      elsif nick.local? then Nickserver::Config.local_source
      else Nickserver::Config.remote_source
      end
    end
  end
end