Class: Kaui::AccountEmail

Inherits:
Base
  • Object
show all
Includes:
ErrorHelper
Defined in:
app/models/kaui/account_email.rb

Instance Attribute Summary

Attributes inherited from Base

#errors

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ErrorHelper

#as_string

Methods inherited from Base

#==, all, #attributes=, camelize, convert_hash_keys, count, define_attr, find, from_json, has_many, has_one, human_attribute_name, lookup_ancestors, #new_record?, #persisted?, #read_attribute_for_validation, #to_hash, to_money, #update_attributes

Constructor Details

#initialize(attributes = {}) ⇒ AccountEmail

Returns a new instance of AccountEmail.



9
10
11
12
13
14
15
16
# File 'app/models/kaui/account_email.rb', line 9

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

Class Method Details

.where(conditions) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/kaui/account_email.rb', line 18

def self.where(conditions)
  begin
     = Kaui::KillbillHelper.(conditions[:account_id]) || []
    return .sort unless conditions[:email].present?

    .each do ||
      return  if .email == conditions[:email]
    end
  rescue => e
    @errors.add(:where, "Error while getting account emails: #{as_string(e)}")
  end
  []
end

Instance Method Details

#<=>(account_email) ⇒ Object



59
60
61
# File 'app/models/kaui/account_email.rb', line 59

def <=>()
  @email <=> .email
end

#destroyObject



42
43
44
45
46
47
48
49
# File 'app/models/kaui/account_email.rb', line 42

def destroy
  begin
    Kaui::KillbillHelper.(self)
    true
  rescue => e
    @errors.add(:destroy, "Error while trying to delete an account email: #{as_string(e)}")
  end
end

#idObject



51
52
53
# File 'app/models/kaui/account_email.rb', line 51

def id
  to_param
end

#saveObject



32
33
34
35
36
37
38
39
40
# File 'app/models/kaui/account_email.rb', line 32

def save
  begin
    Kaui::KillbillHelper.(self)
    true
  rescue => e
    @errors.add(:save, "Error while trying to add an account email: #{as_string(e)}")
    false
  end
end

#to_paramObject



55
56
57
# File 'app/models/kaui/account_email.rb', line 55

def to_param
  @account_id
end