Module: Saucy::Account::ClassMethods

Defined in:
lib/saucy/account.rb

Instance Method Summary collapse

Instance Method Details

#deliver_completed_trial_notificationsObject



143
144
145
146
147
148
149
150
151
152
153
# File 'lib/saucy/account.rb', line 143

def deliver_completed_trial_notifications
  trial_completed.each do ||
    begin
      BillingMailer.completed_trial().deliver
      .notified_of_completed_trial = true
      .save!
    rescue Exception => e
      Airbrake.notify(e)
    end
  end
end

#deliver_expiring_trial_notificationsObject



131
132
133
134
135
136
137
138
139
140
141
# File 'lib/saucy/account.rb', line 131

def deliver_expiring_trial_notifications
  trial_expiring.each do ||
    begin
      BillingMailer.expiring_trial().deliver
      .notified_of_expiration = true
      .save!
    rescue Exception => e
      Airbrake.notify(e)
    end
  end
end

#deliver_new_unactivated_notificationsObject



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/saucy/account.rb', line 119

def deliver_new_unactivated_notifications
  new_unactivated.each do ||
    begin
      BillingMailer.new_unactivated().deliver
      .asked_to_activate = true
      .save!
    rescue Exception => e
      Airbrake.notify(e)
    end
  end
end

#new_unactivatedObject



161
162
163
164
# File 'lib/saucy/account.rb', line 161

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

#search(query) ⇒ Object



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

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

#trialObject



172
173
174
175
# File 'lib/saucy/account.rb', line 172

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

#trial_completedObject



166
167
168
169
170
# File 'lib/saucy/account.rb', line 166

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

#trial_expiringObject



155
156
157
158
159
# File 'lib/saucy/account.rb', line 155

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