Module: Saucy::Account::ClassMethods

Defined in:
lib/saucy/account.rb

Instance Method Summary collapse

Instance Method Details

#deliver_completed_trial_notificationsObject



112
113
114
115
116
117
118
# File 'lib/saucy/account.rb', line 112

def deliver_completed_trial_notifications
  trial_completed.each do ||
    BillingMailer.completed_trial().deliver
    .notified_of_completed_trial = true
    .save!
  end
end

#deliver_expiring_trial_notificationsObject



104
105
106
107
108
109
110
# File 'lib/saucy/account.rb', line 104

def deliver_expiring_trial_notifications
  trial_expiring.each do ||
    BillingMailer.expiring_trial().deliver
    .notified_of_expiration = true
    .save!
  end
end

#deliver_new_unactivated_notificationsObject



96
97
98
99
100
101
102
# File 'lib/saucy/account.rb', line 96

def deliver_new_unactivated_notifications
  new_unactivated.each do ||
    BillingMailer.new_unactivated().deliver
    .asked_to_activate = true
    .save!
  end
end

#new_unactivatedObject



126
127
128
129
# File 'lib/saucy/account.rb', line 126

def new_unactivated
  where(["accounts.created_at <= ?", 7.days.ago]).
    where(:asked_to_activate => false, :activated => false)
end

#search(query) ⇒ Object



91
92
93
94
# File 'lib/saucy/account.rb', line 91

def search(query)
  return [] if query.nil?
  where ['accounts.keyword like :query or accounts.name like :query', { :query => "%#{query}%" }]
end

#trialObject



137
138
139
140
# File 'lib/saucy/account.rb', line 137

def trial
  includes(:plan).
    where(:plans => { :trial => true })
end

#trial_completedObject



131
132
133
134
135
# File 'lib/saucy/account.rb', line 131

def trial_completed
  trial.
    where(:notified_of_completed_trial => false).
    where(["accounts.trial_expires_at <= ?", Time.now])
end

#trial_expiringObject



120
121
122
123
124
# File 'lib/saucy/account.rb', line 120

def trial_expiring
  trial.
    where(:notified_of_expiration => false).
    where(["accounts.trial_expires_at <= ?", 7.days.from_now])
end