Module: BroadcastEvent::Helpers::ExternalSubjects

Included in:
PlateCherrypicked
Defined in:
app/models/broadcast_event/helpers/external_subjects.rb

Overview

Provides support to define subjects that are referring to data stored externally to Sequencescape. The subjects will be built from the properties attribute, instead of the default BroadcastEvent procedure

Instance Method Summary collapse

Instance Method Details

#build_subjectsObject


13
14
15
16
17
18
# File 'app/models/broadcast_event/helpers/external_subjects.rb', line 13

def build_subjects
  properties[:subjects].map do |prop|
    obj = OpenStruct.new(prop)
    BroadcastEvent::SubjectHelpers::Subject.new(obj.role_type, obj)
  end
end

#check_subject_role_type(property, role_type) ⇒ Object


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

def check_subject_role_type(property, role_type)
  unless subjects_with_role_type?(role_type)
    errors.add(property, "is a required subject needed for the event '#{event_type}'")
  end
end

#subjectsObject


7
8
9
10
11
# File 'app/models/broadcast_event/helpers/external_subjects.rb', line 7

def subjects
  return [] unless properties&.key?(:subjects)

  @subjects ||= build_subjects
end

#subjects_with_role_type(role_type) ⇒ Object


20
21
22
# File 'app/models/broadcast_event/helpers/external_subjects.rb', line 20

def subjects_with_role_type(role_type)
  subjects.select { |sub| sub.role_type == role_type }
end

#subjects_with_role_type?(role_type) ⇒ Boolean

Returns:

  • (Boolean)

24
25
26
# File 'app/models/broadcast_event/helpers/external_subjects.rb', line 24

def subjects_with_role_type?(role_type)
  subjects.any? { |sub| sub.role_type == role_type }
end