Class: P2::Router

Inherits:
Object
  • Object
show all
Includes:
P2
Defined in:
lib/p2ruby/router.rb

Overview

Represents external Driver for P2 Router server app

Constant Summary collapse

ROUTER_TITLE =
Regexp.new('P2MQRouter - ')

Constants included from P2

VERSION, VERSION_FILE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Router

Returns a new instance of Router.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/p2ruby/router.rb', line 14

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object



35
36
37
# File 'lib/p2ruby/router.rb', line 35

def method_missing *args
  @app.send *args
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



12
13
14
# File 'lib/p2ruby/router.rb', line 12

def app
  @app
end

#optsObject (readonly)

Returns the value of attribute opts.



12
13
14
# File 'lib/p2ruby/router.rb', line 12

def opts
  @opts
end

Class Method Details

.findObject



7
8
9
10
# File 'lib/p2ruby/router.rb', line 7

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

Instance Method Details

#titleObject



39
40
41
# File 'lib/p2ruby/router.rb', line 39

def title
  @app.main_window.title
end