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.
219 220 221 |
# File 'lib/orator/base.rb', line 219 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.
227 228 229 |
# File 'lib/orator/base.rb', line 227 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.
196 197 198 |
# File 'lib/orator/base.rb', line 196 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.
204 205 206 |
# File 'lib/orator/base.rb', line 204 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.
171 172 173 |
# File 'lib/orator/base.rb', line 171 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.
236 237 238 239 240 |
# File 'lib/orator/base.rb', line 236 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 161 162 163 164 165 |
# File 'lib/orator/base.rb', line 152 def on(event, method = nil, &block) if event.is_a? Hash method = event.values.first event = event.keys.first end 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.
179 180 181 182 183 |
# File 'lib/orator/base.rb', line 179 def register_with(event_handler) event_list.keys.each do |event| event_handler.on("#{self.orator_name}.#{event}", self) end end |