Extract methods to get recipients and valid segments

This way we don't have to use the `send` method in other places, like
the AdminNotification class, and we can change the internal
implementation at any point.
This commit is contained in:
Javi Martín
2021-11-10 20:45:00 +01:00
parent 78e543f6d3
commit 7a028411ab
4 changed files with 34 additions and 4 deletions

View File

@@ -57,8 +57,16 @@ class UserSegments
)
end
def self.valid_segment?(segment)
segment && respond_to?(segment)
end
def self.recipients(segment)
send(segment)
end
def self.user_segment_emails(segment)
UserSegments.send(segment).newsletter.order(:created_at).pluck(:email).compact
recipients(segment).newsletter.order(:created_at).pluck(:email).compact
end
private