Module: Orator::Base::ClassMethods
- Included in:
- Orator::Base
- Defined in:
- lib/orator/base.rb
Instance Method Summary collapse
-
#after(method = nil, &block) ⇒ Object
This handles the after callbacks that our operator needs.
-
#after_list ⇒ Set<Symbol, Block>
This sets up the after list on the first call, and returns the list on the first and subsequent calls.
-
#before(method = nil, &block) ⇒ Object
This handles the before callbacks that our orator needs.
-
#before_list ⇒ Set<Symbol, Block>
This sets up the before list on the first call, and returns the list on the first and subsequent calls.
-
#event_list ⇒ Hash
The event matchings.
-
#inherited(klass) ⇒ Object
This is called when this class is inherited from.
-
#on(event, method = nil, &block) ⇒ void
This registers a method for this orator.
-
#orator_name(value = nil) ⇒ String
This manages the orator’s name.
-
#register_with(event_handler) ⇒ Object
This registers this orator with the event handler by telling it what methods it responds to.
Instance Method Details
#after(method = nil, &block) ⇒ Object
This handles the after callbacks that our operator needs. It can accept a method or a block, and given the two, chooses the method over the block.
214 215 216 |
# File 'lib/orator/base.rb', line 214 def after(method = nil, &block) after_list << (method or block) end |
#after_list ⇒ Set<Symbol, Block>
This sets up the after list on the first call, and returns the list on the first and subsequent calls.
222 223 224 |
# File 'lib/orator/base.rb', line 222 def after_list @after_list ||= Set.new end |
#before(method = nil, &block) ⇒ Object
This handles the before callbacks that our orator needs. It can accept a method or a block, and given the two, chooses the method over the block.
191 192 193 |
# File 'lib/orator/base.rb', line 191 def before(method = nil, &block) before_list << (method or block) end |
#before_list ⇒ Set<Symbol, Block>
This sets up the before list on the first call, and returns the list on the first and subsequent calls.
199 200 201 |
# File 'lib/orator/base.rb', line 199 def before_list @before_list ||= Set.new end |
#event_list ⇒ Hash
The event matchings. The keys are the event name, the values can be an array of mappings or a the mapping itself.
166 167 168 |
# File 'lib/orator/base.rb', line 166 def event_list @event_list ||= {} end |
#inherited(klass) ⇒ Object
This is called when this class is inherited from. We use this to make sure that each subclass inherits the event list as well as the before and after methods.
231 232 233 234 235 |
# File 'lib/orator/base.rb', line 231 def inherited(klass) klass.instance_variable_set(:@event_list, event_list.dup ) klass.instance_variable_set(:@before_list, before_list.dup) klass.instance_variable_set(:@after_list, after_list.dup ) end |
#on(event, method = nil, &block) ⇒ void
This method returns an undefined value.
This registers a method for this orator.
152 153 154 155 156 157 158 159 160 |
# File 'lib/orator/base.rb', line 152 def on(event, method = nil, &block) event_list[event.to_s] ||= [] if block_given? event_list[event.to_s] << block else event_list[event.to_s] << (method || event).to_sym end end |
#orator_name(value = nil) ⇒ String
This manages the orator’s name. If an argument is passed, the name is set to that. Otherwise, it returns the orator’s name.
140 141 142 143 144 145 146 |
# File 'lib/orator/base.rb', line 140 def orator_name(value = nil) if value @_orator_name = value end @_orator_name end |
#register_with(event_handler) ⇒ Object
This registers this orator with the event handler by telling it what methods it responds to.
174 175 176 177 178 |
# File 'lib/orator/base.rb', line 174 def register_with(event_handler) event_list.keys.each do |event| event_handler.on("#{self.orator_name}.#{event}", self) end end |