Class: Evnt::Event
- Inherits:
-
Object
- Object
- Evnt::Event
- Defined in:
- lib/evnt/event.rb
Overview
Events are used to save on a persistent data structure what happends on the system.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
DEPRECATED: Attribute containings the list of attributes of the event.
-
#extras ⇒ Object
readonly
Attribute containings the extra parameters of the event.
-
#extras_attributes ⇒ Object
readonly
Attribute containings the list of extras attributes of the event.
-
#name ⇒ Object
readonly
Attribute containings the name of the event.
-
#payload ⇒ Object
readonly
Attribute containings the payload of the event.
-
#payload_attributes ⇒ Object
readonly
Attribute containings the list of payload attributes of the event.
Class Method Summary collapse
-
.add_handler(handler) ⇒ Object
This function is used to add a new handler to the event from the external.
-
.attributes_are(*attributes) ⇒ Object
DEPRECATED: This function sets the list of attributes for the event.
-
.default_options(options) ⇒ Object
This function sets the default options that should be used by the event.
-
.extras_attributes_are(*attributes) ⇒ Object
This function sets the list of extras attributes for the event.
-
.handlers_are(handlers) ⇒ Object
This function sets the list of handlers for the event.
-
.name_is(name) ⇒ Object
This function sets the name for the event.
-
.payload_attributes_are(*attributes) ⇒ Object
This function sets the list of payload attributes for the event.
-
.to_write_event(&block) ⇒ Object
This function sets the write event function for the event.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Event
constructor
The constructor is used to initialize a new event.
-
#reloaded? ⇒ Boolean
This function tells if the event is reloaded or not.
-
#saved? ⇒ Boolean
This function tells if the event is saved or not.
-
#set_not_saved ⇒ Object
This function can be used to set the event as not saved.
Constructor Details
#initialize(params = {}) ⇒ Event
The constructor is used to initialize a new event. The parameters are validated and added to the payload of the event. The parameters with the _ in their name are not saved on the payload.
Attributes
-
params- The list of parameters for the event. -
_options- The list of options for the event.
Options
-
silent- Boolean value used to avoid the call of the notify method of
handlers.
59 60 61 62 63 64 65 |
# File 'lib/evnt/event.rb', line 59 def initialize(params = {}) _init_event_data(params) _validate_payload _validate_extras _run_event_steps _notify_handlers if @state[:saved] end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
DEPRECATED: Attribute containings the list of attributes of the event.
31 32 33 |
# File 'lib/evnt/event.rb', line 31 def attributes @attributes end |
#extras ⇒ Object (readonly)
Attribute containings the extra parameters of the event.
41 42 43 |
# File 'lib/evnt/event.rb', line 41 def extras @extras end |
#extras_attributes ⇒ Object (readonly)
Attribute containings the list of extras attributes of the event.
26 27 28 |
# File 'lib/evnt/event.rb', line 26 def extras_attributes @extras_attributes end |
#name ⇒ Object (readonly)
Attribute containings the name of the event.
16 17 18 |
# File 'lib/evnt/event.rb', line 16 def name @name end |
#payload ⇒ Object (readonly)
Attribute containings the payload of the event.
36 37 38 |
# File 'lib/evnt/event.rb', line 36 def payload @payload end |
#payload_attributes ⇒ Object (readonly)
Attribute containings the list of payload attributes of the event.
21 22 23 |
# File 'lib/evnt/event.rb', line 21 def payload_attributes @payload_attributes end |
Class Method Details
.add_handler(handler) ⇒ Object
This function is used to add a new handler to the event from the external.
274 275 276 277 278 279 280 |
# File 'lib/evnt/event.rb', line 274 def add_handler(handler) @handlers ||= [] @handlers.push(handler) event_handlers = @handlers define_method('_handlers', -> { return event_handlers }) end |
.attributes_are(*attributes) ⇒ Object
DEPRECATED: This function sets the list of attributes for the event.
251 252 253 254 255 256 257 |
# File 'lib/evnt/event.rb', line 251 def attributes_are(*attributes) @payload_attributes ||= [] @payload_attributes.concat(attributes).uniq! event_payload_attributes = @payload_attributes define_method('_payload_attributes', -> { return event_payload_attributes }) end |
.default_options(options) ⇒ Object
This function sets the default options that should be used by the event.
219 220 221 222 223 224 225 |
# File 'lib/evnt/event.rb', line 219 def () ||= {} .merge!() = define_method('_default_options', -> { return }) end |
.extras_attributes_are(*attributes) ⇒ Object
This function sets the list of extras attributes for the event.
242 243 244 245 246 247 248 |
# File 'lib/evnt/event.rb', line 242 def extras_attributes_are(*attributes) @extras_attributes ||= [] @extras_attributes.concat(attributes).uniq! event_extras_attributes = @extras_attributes define_method('_extras_attributes', -> { return event_extras_attributes }) end |
.handlers_are(handlers) ⇒ Object
This function sets the list of handlers for the event.
260 261 262 263 264 265 266 |
# File 'lib/evnt/event.rb', line 260 def handlers_are(handlers) @handlers ||= [] @handlers.concat(handlers) event_handlers = @handlers define_method('_handlers', -> { return event_handlers }) end |
.name_is(name) ⇒ Object
This function sets the name for the event.
228 229 230 |
# File 'lib/evnt/event.rb', line 228 def name_is(name) define_method('_name', -> { return name }) end |
.payload_attributes_are(*attributes) ⇒ Object
This function sets the list of payload attributes for the event.
233 234 235 236 237 238 239 |
# File 'lib/evnt/event.rb', line 233 def payload_attributes_are(*attributes) @payload_attributes ||= [] @payload_attributes.concat(attributes).uniq! event_payload_attributes = @payload_attributes define_method('_payload_attributes', -> { return event_payload_attributes }) end |
.to_write_event(&block) ⇒ Object
This function sets the write event function for the event.
269 270 271 |
# File 'lib/evnt/event.rb', line 269 def to_write_event(&block) define_method('_write_event', &block) end |
Instance Method Details
#reloaded? ⇒ Boolean
This function tells if the event is reloaded or not. The returned object should be a boolean value corresponding to the presence of evnt value inside the event params.
75 76 77 |
# File 'lib/evnt/event.rb', line 75 def reloaded? @state[:reloaded] end |
#saved? ⇒ Boolean
This function tells if the event is saved or not. As default an event is considered saved. It should be updated to not saved when the to_write_event has some problems.
84 85 86 |
# File 'lib/evnt/event.rb', line 84 def saved? @state[:saved] end |
#set_not_saved ⇒ Object
This function can be used to set the event as not saved. A not saved event should not notify handlers. If the exceptions option is active, it should raise a new error.
93 94 95 96 97 98 |
# File 'lib/evnt/event.rb', line 93 def set_not_saved @state[:saved] = false # raise error if event needs exceptions raise 'Event can not be saved' if [:exceptions] end |