Module: Zif::Traceable
- Included in:
- ExampleApp::CompoundSpriteTest, ExampleApp::WorldLoader, ExampleApp::ZifExampleScene, Game, Layers::LayerGroup
- Defined in:
- lib/zif/traceable.rb
Overview
This mixin helps you wrap calling out to Services::TickTraceService by providing a local #mark method.
Messages logged using this #mark method are automatically prefixed with the class name using #mark_prefix Additionally, it sets up an attribute #tracer_service_name you can use to avoid having to dig into your $services hash. Therefore, the only requirement is that you set up the $services global variable to be an instance of Services::ServiceGroup. This is done for you if you are using Game.
Instance Attribute Summary collapse
-
#tracer_service_name ⇒ Symbol
The name of your Services::TickTraceService as registered in $services (Services::ServiceGroup).
2. Private-ish methods collapse
-
#mark_prefix ⇒ String
private
“<class name>: ”.
Instance Method Summary collapse
-
#mark(msg = 'Oh Hi Mark') ⇒ Object
This marks a section of code you wish to add to your tick traces to #tracer.
-
#mark_and_print(msg = 'Oh Hi Mark', frequency: 1) ⇒ Object
Same as #mark but also sends the output to
puts
so it will appear in your console. -
#tracer(service_name = @tracer_service_name) ⇒ Zif::Services::TickTraceService
Returns your active instance of the Services::TickTraceService.
Instance Attribute Details
#tracer_service_name ⇒ Symbol
Returns The name of your Services::TickTraceService as registered in $services (Services::ServiceGroup).
10 11 12 |
# File 'lib/zif/traceable.rb', line 10 def tracer_service_name @tracer_service_name end |
Instance Method Details
#mark(msg = 'Oh Hi Mark') ⇒ Object
This marks a section of code you wish to add to your tick traces to #tracer. It adds the class name to your message via invoking #mark_prefix for you.
20 21 22 |
# File 'lib/zif/traceable.rb', line 20 def mark(msg='Oh Hi Mark') tracer&.mark("#{mark_prefix}#{msg}") end |
#mark_and_print(msg = 'Oh Hi Mark', frequency: 1) ⇒ Object
Same as #mark but also sends the output to puts
so it will appear in your console.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/zif/traceable.rb', line 27 def mark_and_print(msg='Oh Hi Mark', frequency: 1) full_msg = "#{mark_prefix}#{msg}" case frequency when 6 puts6 full_msg when 60 puts60 full_msg when 600 puts600 full_msg else puts full_msg end mark(msg) end |
#mark_prefix ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This only prints the class name, figure out some way of printing the name of the caller method
Returns “<class name>: ”.
48 49 50 |
# File 'lib/zif/traceable.rb', line 48 def mark_prefix "#{self.class.name}: " end |
#tracer(service_name = @tracer_service_name) ⇒ Zif::Services::TickTraceService
Returns your active instance of the Services::TickTraceService
13 14 15 |
# File 'lib/zif/traceable.rb', line 13 def tracer(service_name=@tracer_service_name) $services[service_name.to_sym] end |