Module: Sandthorn::EventInspector
- Defined in:
- lib/sandthorn/event_inspector.rb
Instance Method Summary collapse
- #events_with_trace_info ⇒ Object
- #has_event?(event_name, options = {}) ⇒ Boolean
- #has_saved_event?(event_name, options = {}) ⇒ Boolean
- #has_unsaved_event?(event_name, options = {}) ⇒ Boolean
Instance Method Details
#events_with_trace_info ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/sandthorn/event_inspector.rb', line 31 def events_with_trace_info saved = Sandthorn.get_aggregate_events self.aggregate_id, self.class unsaved = self.aggregate_events all = saved.concat(unsaved).sort { |a, b| a[:aggregate_version] <=> b[:aggregate_version] } extracted = all.collect do |e| if e[:event_args].nil? && !e[:event_data].nil? data = Sandthorn.deserialize e[:event_data] else data = e[:event_args] end trace = data[:trace] unless data.nil? || !data.is_a?(Hash) {aggregate_version: e[:aggregate_version], event_name: e[:event_name].to_sym, trace: trace } end return extracted end |
#has_event?(event_name, options = {}) ⇒ Boolean
25 26 27 28 29 30 |
# File 'lib/sandthorn/event_inspector.rb', line 25 def has_event? event_name, = {} matching_events = events_with_trace_info.select { |e| e[:event_name] == event_name } event_exists = matching_events.length > 0 trace = has_trace? matching_events, .fetch(:trace, {}) return event_exists && trace end |
#has_saved_event?(event_name, options = {}) ⇒ Boolean
16 17 18 19 20 21 22 23 24 |
# File 'lib/sandthorn/event_inspector.rb', line 16 def has_saved_event? event_name, = {} saved = events_with_trace_info saved.reject! { |e| e[:aggregate_version] >= self.aggregate_events.first[:aggregate_version] } unless self.aggregate_events.empty? matching_events = saved.select { |e| e[:event_name] == event_name } event_exists = matching_events.length > 0 trace = has_trace? matching_events, .fetch(:trace, {}) return event_exists && trace end |
#has_unsaved_event?(event_name, options = {}) ⇒ Boolean
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/sandthorn/event_inspector.rb', line 3 def has_unsaved_event? event_name, = {} unsaved = events_with_trace_info if self.aggregate_events.empty? unsaved = [] else unsaved.reject! { |e| e[:aggregate_version] < self.aggregate_events.first[:aggregate_version] } end matching_events = unsaved.select { |e| e[:event_name] == event_name } event_exists = matching_events.length > 0 trace = has_trace? matching_events, .fetch(:trace, {}) return event_exists && trace end |