Sha256: 7dc9fcbc56f1910ebf6820f30da5979ffd2d9e78bbe93af69d09891f75ba12a4
Contents?: true
Size: 1.43 KB
Versions: 16
Compression:
Stored size: 1.43 KB
Contents
require 'kaui/error_helper' class Kaui::AccountEmail < Kaui::Base include Kaui::ErrorHelper define_attr :account_id define_attr :email def initialize(attributes = {}) super(attributes) # We make Rails believe the id for the AccountEmail is actually the account_id # (this is handy for routes and form_for helpers). Make sure though to mark it as not persisted # (even though @id is not nil) @persisted = false end def self.where(conditions) begin account_emails = Kaui::KillbillHelper.get_account_emails(conditions[:account_id]) || [] return account_emails.sort unless conditions[:email].present? account_emails.each do |account_email| return account_email if account_email.email == conditions[:email] end rescue => e @errors.add(:where, "Error while getting account emails: #{as_string(e)}") end [] end def save begin Kaui::KillbillHelper.add_account_email(self) true rescue => e @errors.add(:save, "Error while trying to add an account email: #{as_string(e)}") false end end def destroy begin Kaui::KillbillHelper.remove_account_email(self) true rescue => e @errors.add(:destroy, "Error while trying to delete an account email: #{as_string(e)}") end end def id to_param end def to_param @account_id end def <=>(account_email) @email <=> account_email.email end end
Version data entries
16 entries across 16 versions & 1 rubygems