Class: Omega::Client::Node

Inherits:
Object show all
Defined in:
lib/omega/client/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#endpointObject

Server endpoint


12
13
14
# File 'lib/omega/client/node.rb', line 12

def endpoint
  @endpoint
end

#handlersObject

Returns the value of attribute handlers


47
48
49
# File 'lib/omega/client/node.rb', line 47

def handlers
  @handlers
end

#rjr_nodeObject

Node to use w/ server communications


15
16
17
# File 'lib/omega/client/node.rb', line 15

def rjr_node
  @rjr_node
end

Instance Method Details

#handle(rjr_method, &bl) ⇒ Object


53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/omega/client/node.rb', line 53

def handle(rjr_method, &bl)
  @handlers ||= Hash.new() { |h,k| h[k] = [] }

  unless @handlers.keys.include?(rjr_method)
    # add handler to rjr_node
    client_node = self
    @rjr_node.dispatcher.handle(rjr_method) { |*args|
      client_node.handlers[rjr_method].each { |h| h.call *args }
      nil
    }
  end

  @handlers[rjr_method] << bl
end

#handles?(rjr_method) ⇒ Boolean


49
50
51
# File 'lib/omega/client/node.rb', line 49

def handles?(rjr_method)
  !@handlers.nil? && @handlers.keys.include?(rjr_method)
end

#invoke(*args) ⇒ Object

Invoke request using the DSL node / endpoint


36
37
38
39
# File 'lib/omega/client/node.rb', line 36

def invoke(*args)
  args.unshift @endpoint unless @endpoint.nil?
  @rjr_node.invoke *args
end

#login(user_id, password) ⇒ Object

Log specified user into the server XXX duplicate of client dsl login, should consolidate into a common client module


71
72
73
74
75
76
77
# File 'lib/omega/client/node.rb', line 71

def (user_id, password)
  user = Users::User.new(:id => user_id,
                         :password => password)
  session = invoke('users::login', user)
  @rjr_node.message_headers['session_id'] = session.id
  nil
end

#notify(*args) ⇒ Object

Invoke notification using the DSL node / endpoint


42
43
44
45
# File 'lib/omega/client/node.rb', line 42

def notify(*args)
  args.unshift @endpoint unless @endpoint.nil?
  @rjr_node.notify *args
end