Class: Motel::Client
- Inherits:
-
Object
- Object
- Motel::Client
- Defined in:
- lib/motel/simrpc_adapter.rb
Overview
Client defines a client endpoint that performs a request against a Motel Server
Instance Attribute Summary collapse
-
#on_location_moved ⇒ Object
writeonly
Set to a callable object that will take a location and distance moved.
-
#on_locations_proximity ⇒ Object
writeonly
Set to a callable object that will take two locations.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Client
constructor
Initialize the client with various args, all of which are passed onto Simrpc::Node constructor.
- #join ⇒ Object
-
#method_missing(method_id, *args) ⇒ Object
pass simrpc method requests right onto the simrpc node.
- #request(target, *args) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Client
Initialize the client with various args, all of which are passed onto Simrpc::Node constructor
147 148 149 150 151 152 |
# File 'lib/motel/simrpc_adapter.rb', line 147 def initialize(args = {}) simrpc_args = args simrpc_args[:destination] = "location-server" @simrpc_node = Simrpc::Node.new(simrpc_args) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *args) ⇒ Object
pass simrpc method requests right onto the simrpc node
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/motel/simrpc_adapter.rb', line 163 def method_missing(method_id, *args) # special case for subsscribe_to_location, if method_id == :subscribe_to_location_movement # add simrpc node id onto args list args.unshift @simrpc_node.id # handle location updates from the server, & issue subscribe request @simrpc_node.handle_method("location_moved") { |location, d, dx, dy, dz| Logger.info "location #{location.id} moved" @on_location_moved.call(location, d, dx, dy, dz) unless @on_location_moved.nil? } elsif method_id == :subscribe_to_locations_proximity # add simrpc node id onto args list args.unshift @simrpc_node.id # handle location proximity events from the server, & issue subscribe request @simrpc_node.handle_method("locations_proximity") { |location1, location2| Logger.info "location #{location1.id}/#{location2.id} proximity" @on_locations_proximity.call(location1, location2) unless @on_locations_proximity.nil? } end @simrpc_node.method_missing(method_id, *args) end |
Instance Attribute Details
#on_location_moved=(value) ⇒ Object (writeonly)
Set to a callable object that will take a location and distance moved
141 142 143 |
# File 'lib/motel/simrpc_adapter.rb', line 141 def on_location_moved=(value) @on_location_moved = value end |
#on_locations_proximity=(value) ⇒ Object (writeonly)
Set to a callable object that will take two locations
144 145 146 |
# File 'lib/motel/simrpc_adapter.rb', line 144 def on_locations_proximity=(value) @on_locations_proximity = value end |
Instance Method Details
#join ⇒ Object
154 155 156 |
# File 'lib/motel/simrpc_adapter.rb', line 154 def join @simrpc_node.join end |
#request(target, *args) ⇒ Object
158 159 160 |
# File 'lib/motel/simrpc_adapter.rb', line 158 def request(target, *args) method_missing(target, *args) end |