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
- #enable_writes! {|_self| ... } ⇒ Object
- #extend_validation ⇒ Object
- #perform_transition_checks ⇒ Object
- #skip_apply_check ⇒ Object
- #skip_dispatcher ⇒ Object
Instance Method Details
#aggregate ⇒ Object
137 138 139 |
# File 'lib/eventsimple/event.rb', line 137 def aggregate public_send(_aggregate_klass.model_name.element) end |
#aggregate=(aggregate) ⇒ Object
141 142 143 |
# File 'lib/eventsimple/event.rb', line 141 def aggregate=(aggregate) public_send(:"#{_aggregate_klass.model_name.element}=", aggregate) end |
#apply(aggregate) ⇒ Object
95 |
# File 'lib/eventsimple/event.rb', line 95 def apply(aggregate); end |
#apply_and_persist ⇒ Object
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/eventsimple/event.rb', line 122 def apply_and_persist (aggregate) apply(aggregate) aggregate.enable_writes! aggregate.save! aggregate.readonly! self.aggregate = aggregate end |
#apply_timestamps(aggregate) ⇒ Object
101 102 103 104 |
# File 'lib/eventsimple/event.rb', line 101 def (aggregate) aggregate.created_at ||= created_at aggregate.updated_at = created_at end |
#can_apply?(_aggregate) ⇒ Boolean
97 98 99 |
# File 'lib/eventsimple/event.rb', line 97 def can_apply?(_aggregate) true end |
#deleted? ⇒ Boolean
91 92 93 |
# File 'lib/eventsimple/event.rb', line 91 def deleted? false end |
#dispatch ⇒ Object
133 134 135 |
# File 'lib/eventsimple/event.rb', line 133 def dispatch EventDispatcher.dispatch(self) unless skip_dispatcher end |
#enable_writes! {|_self| ... } ⇒ Object
145 146 147 148 149 150 151 152 153 |
# File 'lib/eventsimple/event.rb', line 145 def enable_writes!(&block) was_readonly = @readonly @readonly = false return unless block yield self @readonly = was_readonly end |
#extend_validation ⇒ Object
117 118 119 120 |
# File 'lib/eventsimple/event.rb', line 117 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
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/eventsimple/event.rb', line 106 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
87 88 89 |
# File 'lib/eventsimple/event.rb', line 87 def skip_apply_check @skip_apply_check || false end |
#skip_dispatcher ⇒ Object
83 84 85 |
# File 'lib/eventsimple/event.rb', line 83 def skip_dispatcher @skip_dispatcher || false end |