Class: Orator::Base Abstract
- Inherits:
-
Object
- Object
- Orator::Base
- Extended by:
- ClassMethods
- Defined in:
- lib/orator/base.rb
Overview
A base for the orators to split off of. It handles contexts and running methods. Most of the methods defined in this class are prefixed with two dashes to prevent polluting the namespace.
Direct Known Subclasses
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#__event_list ⇒ Hash
A map of the events that determine how this class will respond.
-
#__method_exists?(method) ⇒ Set<Symbol, Proc>?
Checks the event list to see if this class responds to it.
-
#__trigger(event, *args) ⇒ Array<Object>?
This triggers an event if it’s defined on this orator.
-
#event ⇒ String
Returns the current event that the orator is handling in ‘event` form.
-
#full_event ⇒ String
Returns the current event that the orator is handling in ‘orator.event` form.
-
#initialize(context) ⇒ Base
constructor
Initialize the orator with the context.
-
#method_missing(method, *args, &block) ⇒ Object
Handles missing methods by delegating them to the context.
-
#prevent_event ⇒ Object
This tells the orator to not execute the events in the class.
-
#respond_to_missing?(method, include_private = false) ⇒ Boolean
Lets Ruby know that there are some undefined methods on this class.
-
#send(*args, &block) ⇒ Object
This forwards #send on to the context.
Methods included from ClassMethods
after, after_list, before, before_list, event_list, inherited, on, orator_name, register_with
Constructor Details
#initialize(context) ⇒ Base
Initialize the orator with the context.
13 14 15 |
# File 'lib/orator/base.rb', line 13 def initialize(context) @__context = context end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Handles missing methods by delegating them to the context. Should never be called directly.
77 78 79 80 81 |
# File 'lib/orator/base.rb', line 77 def method_missing(method, *args, &block) super unless respond_to_missing?(method) @__context.public_send(method, *args, &block) end |
Instance Method Details
#__event_list ⇒ Hash
A map of the events that determine how this class will respond.
63 64 65 |
# File 'lib/orator/base.rb', line 63 def __event_list self.class.event_list end |
#__method_exists?(method) ⇒ Set<Symbol, Proc>?
Checks the event list to see if this class responds to it.
55 56 57 |
# File 'lib/orator/base.rb', line 55 def __method_exists?(method) __event_list[method] end |
#__trigger(event, *args) ⇒ Array<Object>?
This triggers an event if it’s defined on this orator. If it is not defined, it raises an error.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/orator/base.rb', line 24 def __trigger(event, *args) orator = event[0..event.index('.')-1] method_name = event[event.index('.')+1..-1] __check_event(orator, method_name) @event = [orator, method_name] __run_callbacks(:before, args) out = __run_event(method_name, args) unless @__prevent_event __run_callbacks(:after, args) out end |
#event ⇒ String
Returns the current event that the orator is handling in ‘event` form.
48 49 50 |
# File 'lib/orator/base.rb', line 48 def event @event[1] end |
#full_event ⇒ String
Returns the current event that the orator is handling in ‘orator.event` form.
41 42 43 |
# File 'lib/orator/base.rb', line 41 def full_event @event.join('.') end |
#prevent_event ⇒ Object
This tells the orator to not execute the events in the class. This should only be called in a ‘before` block.
69 70 71 |
# File 'lib/orator/base.rb', line 69 def prevent_event @__prevent_event = true end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
Lets Ruby know that there are some undefined methods on this class.
86 87 88 |
# File 'lib/orator/base.rb', line 86 def respond_to_missing?(method, include_private = false) @__context.respond_to?(method, include_private) end |
#send(*args, &block) ⇒ Object
This forwards #send on to the context.
93 94 95 |
# File 'lib/orator/base.rb', line 93 def send(*args, &block) @__context.send(*args, &block) end |