Module: EventMachine::UCEngine::Brick::ClassMethods
- Defined in:
- lib/em-ucengine/brick.rb
Overview
Methods defined here will be made available as class methods on the class including Brick. Some class variables are pushed as well: @@routes, @@bricks, @@bootstrap.
Class Method Summary collapse
Instance Method Summary collapse
-
#bootstrap(&block) ⇒ Object
Define a bootstrap block, which will be called before subscribing to events.
-
#on(route) {|Event| ... } ⇒ Object
Define an event handler.
-
#use(name) ⇒ Object
Add a sub-brick to the current brick.
Class Method Details
.extended(klass) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/em-ucengine/brick.rb', line 26 def self.extended(klass) klass.class_eval { class_variable_set("@@routes", {}) class_variable_set("@@bricks", []) class_variable_set("@@bootstrap", Proc.new {}) } end |
Instance Method Details
#bootstrap(&block) ⇒ Object
Define a bootstrap block, which will be called before subscribing to events.
36 37 38 |
# File 'lib/em-ucengine/brick.rb', line 36 def bootstrap(&block) class_variable_set("@@bootstrap", block) end |
#on(route) {|Event| ... } ⇒ Object
Define an event handler.
49 50 51 52 53 |
# File 'lib/em-ucengine/brick.rb', line 49 def on(route, &callback) routes = class_variable_get("@@routes") routes[route] ||= [] routes[route] << callback end |
#use(name) ⇒ Object
Add a sub-brick to the current brick.
60 61 62 |
# File 'lib/em-ucengine/brick.rb', line 60 def use(name) class_variable_get("@@bricks") << name end |