Sha256: 6fac075c5f81bd6c9e8a78d806036bc03de4fac5a391f6c2b55824bc797ddc72

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

module P2
  # Represents external Driver for P2 Router server app
  class Router
    ROUTER_TITLE = Regexp.new('P2MQRouter - ')
    include P2

    def self.find
      router = WinGui::App.find :title => ROUTER_TITLE
      router ? new(:app => router) : nil
    end

    attr_reader :opts, :app

    def initialize opts = {}
      @opts = opts.dup
      if @opts[:app]
        @app = @opts[:app]
      else
        @opts[:ini] = Pathname(@opts[:ini] || @opts[:ini_file] || "./client_router.ini")
        error "Wrong ini file name" unless @opts[:ini].expand_path.exist? || @opts[:args]

        @opts[:title] ||= ROUTER_TITLE
        @opts[:path] ||= @opts[:dir] && @opts[:dir] + 'P2MQRouter.exe'
        @opts[:args] ||= "/ini:#{@opts[:ini]}"
        @opts[:timeout] ||= 3

        @app = WinGui::App.launch(:dir => @opts[:dir],
                                  :path => @opts[:path],
                                  :args => @opts[:args],
                                  :title => @opts[:title],
                                  :timeout => @opts[:timeout])
      end
    end

    def method_missing *args
      @app.send *args
    end

    def title
      @app.main_window.title
    end

  end # class Router
end # module P2

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
p2ruby-0.1.1 lib/p2ruby/router.rb
p2ruby-0.1.0 lib/p2ruby/router.rb