Class: Stenotype::Event
- Inherits:
-
Object
- Object
- Stenotype::Event
- Defined in:
- lib/stenotype/event.rb
Overview
Event represents a triggered event
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#dispatcher ⇒ Object
readonly
Returns the value of attribute dispatcher.
-
#eval_context ⇒ Object
readonly
Returns the value of attribute eval_context.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.emit!(name, attributes = {}, eval_context: {}, dispatcher: Stenotype.config.dispatcher) ⇒ Stenotype::Event
Delegates event to instance of Event.
Instance Method Summary collapse
-
#emit! ⇒ Object
Emits a Event.
-
#initialize(name, attributes = {}, eval_context: {}, dispatcher: Stenotype.config.dispatcher) ⇒ Stenotype::Event
constructor
An instance of event.
Constructor Details
#initialize(name, attributes = {}, eval_context: {}, dispatcher: Stenotype.config.dispatcher) ⇒ Stenotype::Event
Returns An instance of event.
52 53 54 55 56 57 |
# File 'lib/stenotype/event.rb', line 52 def initialize(name, attributes = {}, eval_context: {}, dispatcher: Stenotype.config.dispatcher) @name = name @attributes = attributes @eval_context = eval_context @dispatcher = dispatcher.new end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
38 39 40 |
# File 'lib/stenotype/event.rb', line 38 def attributes @attributes end |
#dispatcher ⇒ Object (readonly)
Returns the value of attribute dispatcher.
38 39 40 |
# File 'lib/stenotype/event.rb', line 38 def dispatcher @dispatcher end |
#eval_context ⇒ Object (readonly)
Returns the value of attribute eval_context.
38 39 40 |
# File 'lib/stenotype/event.rb', line 38 def eval_context @eval_context end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
38 39 40 |
# File 'lib/stenotype/event.rb', line 38 def name @name end |
Class Method Details
.emit!(name, attributes = {}, eval_context: {}, dispatcher: Stenotype.config.dispatcher) ⇒ Stenotype::Event
Delegates event to instance of Stenotype::Event.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/stenotype/event.rb', line 20 def self.emit!(name, attributes = {}, eval_context: {}, dispatcher: Stenotype.config.dispatcher) return unless Stenotype.config.enabled begin event = new(name, attributes, eval_context: eval_context, dispatcher: dispatcher) event.emit! event rescue StandardError => exception # # @todo This is a temporary solution to enable conditional logger fetching # needs a fix to use default Spicerack::Configuration functionality # Stenotype::Configuration.logger.error(exception) raise Stenotype::Error unless Stenotype.config.graceful_error_handling end end |
Instance Method Details
#emit! ⇒ Object
Emits a Stenotype::Event.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/stenotype/event.rb', line 66 def emit! return unless Stenotype.config.enabled begin dispatcher.publish(self) rescue StandardError => exception # # @todo This is a temporary solution to enable conditional logger fetching # needs a fix to use default Spicerack::Configuration functionality # Stenotype::Configuration.logger.error(exception) raise Stenotype::Error unless Stenotype.config.graceful_error_handling end end |