Class: BroadcastEvent

Inherits:
ApplicationRecord show all
Extended by:
MetadataHelpers::MetadatableClassMethods, RenderHelpers::RenderableClassMethods, SubjectHelpers::SubjectableClassMethods
Includes:
Uuid::Uuidable
Defined in:
app/models/broadcast_event.rb

Overview

Abstract class used to generate events; use subclass to specify how your particular event is generated.

See Also:

Defined Under Namespace

Modules: Helpers, MetadataHelpers, RenderHelpers, SubjectHelpers Classes: AssetAudit, LabEvent, LabwareFailed, LabwareReceived, LibraryComplete, LibraryStart, OrderMade, PlateCherrypicked, PlateLibraryComplete, QcAssay, SampleManifestCreated, SampleManifestUpdated, SequencingComplete, SequencingStart

Constant Summary collapse

EVENT_JSON_ROOT =
'event'
UNKNOWN_USER_IDENTIFIER =
'UNKNOWN'

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SubjectHelpers::SubjectableClassMethods

has_subject, has_subjects, seed_class, seed_subject, subject_associations

Methods included from MetadataHelpers::MetadatableClassMethods

has_metadata, metadata_finders

Methods included from RenderHelpers::RenderableClassMethods

render_class

Methods included from Uuid::Uuidable

included, #unsaved_uuid!, #uuid

Methods inherited from ApplicationRecord

convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Squishify

extended

Class Attribute Details

.event_typeObject (readonly)

Returns the value of attribute event_type.


72
73
74
# File 'app/models/broadcast_event.rb', line 72

def event_type
  @event_type
end

Class Method Details

.set_event_type(event_type) ⇒ String

Use in subclasses to specify a fixed event type

Parameters:

  • event_type (String)

    The event type to use for this subclass

Returns:

  • (String)

    The event type


66
67
68
# File 'app/models/broadcast_event.rb', line 66

def self.set_event_type(event_type)
  @event_type = event_type
end

Instance Method Details

#event_typeString

Override in subclasses if you want dynamic event types

Returns:

  • (String)

    The value of the event_type key in the generated message


57
58
59
# File 'app/models/broadcast_event.rb', line 57

def event_type
  self.class.event_type
end

#json_rootString

Returns the root of the generated json object. 'event'.

Returns:

  • (String)

    the root of the generated json object. 'event'


51
52
53
# File 'app/models/broadcast_event.rb', line 51

def json_root
  EVENT_JSON_ROOT
end

#metadataObject

Returns a hash of all metadata


40
41
42
# File 'app/models/broadcast_event.rb', line 40

def 
  self.class..map { |mf| mf.for(seed, self) }.to_h
end

#routing_keyString

Routing key generated for the broadcasted event.

Returns:

  • (String)

    Routing key. eg. event.library_created.123


46
47
48
# File 'app/models/broadcast_event.rb', line 46

def routing_key
  "event.#{event_type}.#{id}"
end

#subjectsObject

Returns an array of all subjects


35
36
37
# File 'app/models/broadcast_event.rb', line 35

def subjects
  self.class.subject_associations.flat_map { |sa| sa.for(seed, self) }.select(&:broadcastable?)
end

#user_identifierObject

Prefer email, fall back to login if missing


28
29
30
31
32
# File 'app/models/broadcast_event.rb', line 28

def user_identifier
  return UNKNOWN_USER_IDENTIFIER if user.nil? # User has probably been deleted

  user.email.presence || user.
end