Module: BroadcastEvent::SubjectHelpers::SubjectableClassMethods

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

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)

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

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)

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

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


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

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)


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

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

#subject_associationsObject


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

def subject_associations
  @subject_associations ||= []
end