Module: Omega::Client::HasLocation

Included in:
Ship, Station
Defined in:
lib/omega/client/entities/location.rb

Overview

Include the HasLocation module in classes to associate instances of the class w/ a server side location.

Examples:

class Ship
  include Trackable
  include HasLocation
  entity_type Manufactured::Ship
  get_method "manufactured::get_entity"
end

s = Ship.get('ship1')
s.handle_event(:movement) { |sh|
  puts "#{sh.id} moved to #{sh.location}"
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

The class methods below will be defined on the class including this module

Defines an event to track entity/location movement which the client may optionally register a handler for

See Also:

  • ClassMethods

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/omega/client/entities/location.rb', line 43

def self.included(base)
  base.entity_event \
    :movement =>
      { :setup =>
          proc { |distance|
            node.invoke("motel::track_movement",
                        self.entity.location.id, distance)
          },
        :notification => "motel::on_movement",
        :match =>
          proc { |entity,l|
            entity.location.id == l.id
          },
        :update =>
          proc { |entity,l|
            entity.entity.location = l
          }
      }
end

Instance Method Details

#locationMotel::Location

Return latest location


32
33
34
# File 'lib/omega/client/entities/location.rb', line 32

def location
  node.invoke('motel::get_location', 'with_id', self.entity.location.id)
end