Class: Users::InProductMarketingEmail

Inherits:
ApplicationRecord show all
Includes:
BulkInsertSafe
Defined in:
app/models/users/in_product_marketing_email.rb

Constant Summary collapse

BUILD_IOS_APP_GUIDE =
'build_ios_app_guide'
CAMPAIGNS =
[BUILD_IOS_APP_GUIDE].freeze
INACTIVE_TRACK_NAMES =

Tracks we don't send emails for (e.g. unsuccessful experiment). These are kept since we already have DB records that use the enum value.

%w(invite_team).freeze
ACTIVE_TRACKS =
tracks.except(*INACTIVE_TRACK_NAMES)

Constants included from BulkInsertSafe

BulkInsertSafe::ALLOWED_CALLBACKS, BulkInsertSafe::DEFAULT_BATCH_SIZE, BulkInsertSafe::MethodNotAllowedError, BulkInsertSafe::PrimaryKeySetError

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Class Method Summary collapse

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.distinct_users_sqlObject


65
66
67
68
# File 'app/models/users/in_product_marketing_email.rb', line 65

def self.distinct_users_sql
  name = users_table.table_name
  Arel.sql("DISTINCT ON(#{name}.id) #{name}.*")
end

.for_campaign(campaign) ⇒ Object


81
82
83
# File 'app/models/users/in_product_marketing_email.rb', line 81

def self.for_campaign(campaign)
  arel_table[:campaign].eq(campaign)
end

.for_track_and_series(track, series) ⇒ Object


85
86
87
88
# File 'app/models/users/in_product_marketing_email.rb', line 85

def self.for_track_and_series(track, series)
  arel_table[:track].eq(ACTIVE_TRACKS[track])
    .and(arel_table[:series]).eq(series)
end

.for_userObject


77
78
79
# File 'app/models/users/in_product_marketing_email.rb', line 77

def self.for_user
  arel_table[:user_id].eq(users_table[:id])
end

.save_cta_click(user, track, series) ⇒ Object


90
91
92
93
94
# File 'app/models/users/in_product_marketing_email.rb', line 90

def self.save_cta_click(user, track, series)
  email = for_user_with_track_and_series(user, track, series).take

  email.update(cta_clicked_at: Time.zone.now) if email && email.cta_clicked_at.blank?
end

.users_tableObject


61
62
63
# File 'app/models/users/in_product_marketing_email.rb', line 61

def self.users_table
  User.arel_table
end

.users_without_records(condition) ⇒ Object


70
71
72
73
74
75
# File 'app/models/users/in_product_marketing_email.rb', line 70

def self.users_without_records(condition)
  arel_join = users_table.join(arel_table, Arel::Nodes::OuterJoin).on(condition)
  joins(arel_join.join_sources)
    .where(in_product_marketing_emails: { id: nil })
    .select(distinct_users_sql)
end