Module: Eventsimple::Event::InstanceMethods
- Defined in:
- lib/eventsimple/event.rb
Instance Method Summary collapse
- #aggregate ⇒ Object
- #aggregate=(aggregate) ⇒ Object
- #apply(aggregate) ⇒ Object
- #apply_and_persist ⇒ Object
- #apply_timestamps(aggregate) ⇒ Object
- #can_apply?(_aggregate) ⇒ Boolean
- #deleted? ⇒ Boolean
- #dispatch ⇒ Object
- #extend_validation ⇒ Object
- #perform_transition_checks ⇒ Object
- #skip_apply_check ⇒ Object
- #skip_dispatcher ⇒ Object
Instance Method Details
#aggregate ⇒ Object
141 142 143 |
# File 'lib/eventsimple/event.rb', line 141 def aggregate public_send(_aggregate_klass.model_name.element) end |
#aggregate=(aggregate) ⇒ Object
145 146 147 |
# File 'lib/eventsimple/event.rb', line 145 def aggregate=(aggregate) public_send(:"#{_aggregate_klass.model_name.element}=", aggregate) end |
#apply(aggregate) ⇒ Object
98 |
# File 'lib/eventsimple/event.rb', line 98 def apply(aggregate); end |
#apply_and_persist ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/eventsimple/event.rb', line 125 def apply_and_persist (aggregate) apply(aggregate) Eventsimple.enable_writes! do aggregate.save! end aggregate.readonly! self.aggregate = aggregate end |
#apply_timestamps(aggregate) ⇒ Object
104 105 106 107 |
# File 'lib/eventsimple/event.rb', line 104 def (aggregate) aggregate.created_at ||= created_at aggregate.updated_at = created_at end |
#can_apply?(_aggregate) ⇒ Boolean
100 101 102 |
# File 'lib/eventsimple/event.rb', line 100 def can_apply?(_aggregate) true end |
#deleted? ⇒ Boolean
94 95 96 |
# File 'lib/eventsimple/event.rb', line 94 def deleted? false end |
#dispatch ⇒ Object
137 138 139 |
# File 'lib/eventsimple/event.rb', line 137 def dispatch EventDispatcher.dispatch(self) unless skip_dispatcher end |
#extend_validation ⇒ Object
120 121 122 123 |
# File 'lib/eventsimple/event.rb', line 120 def extend_validation validate_form = self.class.instance_variable_get(:@validate_with) self.aggregate = aggregate.extend(validate_form) if validate_form end |
#perform_transition_checks ⇒ Object
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/eventsimple/event.rb', line 109 def perform_transition_checks return if skip_apply_check return if can_apply?(aggregate) _on_invalid_transition.call( Eventsimple::InvalidTransition.new(self.class), ) raise ActiveRecord::Rollback end |
#skip_apply_check ⇒ Object
90 91 92 |
# File 'lib/eventsimple/event.rb', line 90 def skip_apply_check @skip_apply_check || false end |
#skip_dispatcher ⇒ Object
86 87 88 |
# File 'lib/eventsimple/event.rb', line 86 def skip_dispatcher @skip_dispatcher || false end |