Module: Studio::Newsletter

Defined in:
lib/studio/newsletter.rb

Constant Summary collapse

COLUMNS =

The columns a host must have for any of this to mean anything. The profile row declares the same pair in requires:, so a host without them silently gets no newsletter card rather than a NoMethodError on every page load.

%i[joined_email_list_at left_email_list_at].freeze

Class Method Summary collapse

Class Method Details

.ever_joined?(user) ⇒ Boolean

Has this account EVER been on the list? Distinct from subscribed?, and the question a once-ever welcome bonus asks. The engine does not pay bonuses; it answers the question so a consumer that does never has to reach past this module into the columns.

Returns:

  • (Boolean)


57
58
59
# File 'lib/studio/newsletter.rb', line 57

def ever_joined?(user)
  serves?(user) && !user.joined_email_list_at.nil?
end

.needs_email?(user) ⇒ Boolean

A newsletter needs somewhere to send. An account with no address on file — a wallet-only sign-in, which turf-monster has plenty of — has to supply one before it can subscribe, so the UI asks rather than failing the submit.

Returns:

  • (Boolean)


64
65
66
67
68
# File 'lib/studio/newsletter.rb', line 64

def needs_email?(user)
  return false unless serves?(user)

  !user.respond_to?(:email) || user.email.to_s.strip.empty?
end

.serves?(user) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
# File 'lib/studio/newsletter.rb', line 32

def serves?(user)
  return false if user.nil?

  COLUMNS.all? { |column| user.respond_to?(column) }
end

.subscribed?(user) ⇒ Boolean

On the list right now.

joined > left rather than left.nil?, because a REJOIN leaves both set and the later date wins. Reading only left_email_list_at.nil? would call every rejoined account unsubscribed forever.

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
# File 'lib/studio/newsletter.rb', line 43

def subscribed?(user)
  return false unless serves?(user)

  joined = user.joined_email_list_at
  return false if joined.nil?

  left = user.left_email_list_at
  left.nil? || joined > left
end