Module: BroadcastEvent::SubjectHelpers::SubjectableClassMethods

Included in:
BroadcastEvent
Defined in:
app/models/broadcast_event/subject_helpers.rb

Overview

rubocop:todo Style/Documentation

Instance Method Summary collapse

Instance Method Details

#has_subject(role_type, method = nil, &block) ⇒ Object

Defines a new subject, specifies the role type and either a method on the seed that will return the subject, or a block that gets passed the seed, and will return the subject.

Raises:

  • (StandardError)

113
114
115
116
117
118
# File 'app/models/broadcast_event/subject_helpers.rb', line 113

def has_subject(role_type, method = nil, &block)
  return subject_associations << SimpleSingleSubjectAssociation.new(role_type, method) unless method.nil?
  return subject_associations << BlockSingleSubjectAssociation.new(role_type, &block) unless block.nil?

  raise StandardError, "No block or method defined for #{role_type} on #{name}"
end

#has_subjects(role_type, method = nil, &block) ⇒ Object

Used when you explicitly expect to receive more than one subject

Raises:

  • (StandardError)

121
122
123
124
125
126
# File 'app/models/broadcast_event/subject_helpers.rb', line 121

def has_subjects(role_type, method = nil, &block)
  return subject_associations << SimpleManySubjectAssociation.new(role_type, method) unless method.nil?
  return subject_associations << BlockManySubjectAssociation.new(role_type, &block) unless block.nil?

  raise StandardError, "No block or method defined for #{role_type} on #{name}"
end

#seed_class(seed_class) ⇒ Object

The class expected to seed the messenger


102
103
104
# File 'app/models/broadcast_event/subject_helpers.rb', line 102

def seed_class(seed_class)
  @seed_class = seed_class
end

#seed_subject(role_type) ⇒ Object

The role type that will identify the seed (if applicable)


107
108
109
# File 'app/models/broadcast_event/subject_helpers.rb', line 107

def seed_subject(role_type)
  subject_associations << SeedSubjectAssociation.new(role_type)
end

#subject_associationsObject


128
129
130
# File 'app/models/broadcast_event/subject_helpers.rb', line 128

def subject_associations
  @subject_associations ||= []
end