Class: GameOverseer::Service
- Inherits:
-
Object
- Object
- GameOverseer::Service
- Defined in:
- lib/gameoverseer/services/service.rb
Overview
Services are at the heart on GameOverseer
Subclass this class to implement a service
Instance Attribute Summary collapse
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#safe_methods ⇒ Object
readonly
Returns the value of attribute safe_methods.
Class Method Summary collapse
-
.inherited(subclass) ⇒ Object
Adds the class that subclassed this class to a list for activation later.
Instance Method Summary collapse
-
#after(milliseconds, &block) ⇒ Object
Calls Proc after milliseconds have passed, async.
-
#channel_manager ⇒ ChannelManager
Active instance of ChannelManager.
-
#client_manager ⇒ ClientManager
Current instance of ClientManager.
-
#data_to_method(data) ⇒ Object
Uses the ‘mode’ from a packet to call the method of the same name.
-
#enable ⇒ Object
Called when services are first initialized, put active code here, in a thread.
-
#every(milliseconds, &block) ⇒ Object
Calls Proc immediately then every milliseconds, async.
-
#initialize ⇒ Service
constructor
This method should not be overridden, you should instead implement #setup with no arguments.
-
#log(string, color = Gosu::Color::RED) ⇒ Object
String to be logged.
-
#message_manager ⇒ MessageManager
Instance of MessageManager.
-
#process(data) ⇒ Object
Called when a message is recieved for this channel.
-
#set_safe_methods(array) ⇒ Object
Sets methods that are safe for #data_to_method to call.
-
#setup ⇒ Object
Called before #enable there should be no active code here, only setup variables.
- #version ⇒ Object
Constructor Details
Instance Attribute Details
#client_id ⇒ Object
Returns the value of attribute client_id.
7 8 9 |
# File 'lib/gameoverseer/services/service.rb', line 7 def client_id @client_id end |
#safe_methods ⇒ Object (readonly)
Returns the value of attribute safe_methods.
8 9 10 |
# File 'lib/gameoverseer/services/service.rb', line 8 def safe_methods @safe_methods end |
Class Method Details
.inherited(subclass) ⇒ Object
Adds the class that subclassed this class to a list for activation later
12 13 14 15 |
# File 'lib/gameoverseer/services/service.rb', line 12 def self.inherited(subclass) Services.register(subclass) GameOverseer::Console.log "Service> added '#{subclass}' to Services::List." end |
Instance Method Details
#after(milliseconds, &block) ⇒ Object
Calls Proc after milliseconds have passed, async.
98 99 100 101 102 103 |
# File 'lib/gameoverseer/services/service.rb', line 98 def after(milliseconds, &block) Thread.new do sleep(milliseconds/1000.0) block.call end end |
#channel_manager ⇒ ChannelManager
Returns Active instance of ChannelManager.
58 59 60 |
# File 'lib/gameoverseer/services/service.rb', line 58 def channel_manager ChannelManager.instance end |
#client_manager ⇒ ClientManager
Returns Current instance of ClientManager.
68 69 70 |
# File 'lib/gameoverseer/services/service.rb', line 68 def client_manager ClientManager.instance end |
#data_to_method(data) ⇒ Object
Uses the ‘mode’ from a packet to call the method of the same name
74 75 76 77 78 79 80 81 |
# File 'lib/gameoverseer/services/service.rb', line 74 def data_to_method(data) raise "No safe methods defined!" unless @safe_methods.size > 0 @safe_methods.each do |method| if data['mode'] == method.to_s self.send(data['mode'], data) end end end |
#enable ⇒ Object
Called when services are first initialized, put active code here, in a thread.
32 33 |
# File 'lib/gameoverseer/services/service.rb', line 32 def enable end |
#every(milliseconds, &block) ⇒ Object
Calls Proc immediately then every milliseconds, async.
86 87 88 89 90 91 92 93 |
# File 'lib/gameoverseer/services/service.rb', line 86 def every(milliseconds, &block) Thread.new do loop do block.call sleep(milliseconds/1000.0) end end end |
#log(string, color = Gosu::Color::RED) ⇒ Object
String to be logged
108 109 110 |
# File 'lib/gameoverseer/services/service.rb', line 108 def log(string, color = Gosu::Color::RED) GameOverseer::Console.log_with_color(string, color) end |
#message_manager ⇒ MessageManager
Returns Instance of MessageManager.
63 64 65 |
# File 'lib/gameoverseer/services/service.rb', line 63 def MessageManager.instance end |
#process(data) ⇒ Object
Called when a message is recieved for this channel.
37 38 |
# File 'lib/gameoverseer/services/service.rb', line 37 def process(data) end |
#set_safe_methods(array) ⇒ Object
Sets methods that are safe for #data_to_method to call
52 53 54 55 |
# File 'lib/gameoverseer/services/service.rb', line 52 def set_safe_methods(array) raise "argument must be an array of strings or symbols" unless array.is_a?(Array) @safe_methods = array end |
#setup ⇒ Object
Called before #enable there should be no active code here, only setup variables.
28 29 |
# File 'lib/gameoverseer/services/service.rb', line 28 def setup end |
#version ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/gameoverseer/services/service.rb', line 40 def version # Please use the sematic versioning system, # http://semver.org # # e.g. # "1.5.9" # (Major.Minor.Patch) "0.0.0-default" end |