Module: EntityProjection::ApplyMacro
- Defined in:
- lib/entity_projection/entity_projection.rb
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
- #apply_macro(event_class, &blk) ⇒ Object (also: #apply)
- #define_apply_method(event_class, &blk) ⇒ Object
- #logger ⇒ Object
Instance Method Details
#apply_macro(event_class, &blk) ⇒ Object Also known as: apply
69 70 71 72 |
# File 'lib/entity_projection/entity_projection.rb', line 69 def apply_macro(event_class, &blk) define_apply_method(event_class, &blk) event_registry.register(event_class) end |
#define_apply_method(event_class, &blk) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/entity_projection/entity_projection.rb', line 75 def define_apply_method(event_class, &blk) apply_method_name = handler_name(event_class) if blk.nil? error_msg = "Handler for #{event_class.name} is not correctly defined. It must have a block." logger.error { error_msg } raise Error, error_msg end send(:define_method, apply_method_name, &blk) apply_method = instance_method(apply_method_name) unless apply_method.arity == 1 error_msg = "Handler for #{event_class.name} is not correctly defined. It can only have a single parameter." logger.error { error_msg } raise Error, error_msg end apply_method_name end |
#logger ⇒ Object
65 66 67 |
# File 'lib/entity_projection/entity_projection.rb', line 65 def logger @logger ||= Log.get(self) end |