Class: Signup

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Conversion, ActiveModel::Validations
Defined in:
app/models/signup.rb

Overview

Responsible for handling the combo User/Account creation. Also deals with Account creation when signing in as an existing User.

Constant Summary collapse

FIELDS =
{
  :account => {
    :name    => :account_name,
    :keyword => :keyword,
    :cardholder_name => :cardholder_name, 
    :billing_email => :billing_email, 
    :card_number => :card_number, 
    :expiration_month => :expiration_month, 
    :expiration_year => :expiration_year,
    :verification_code => :verification_code,
    :plan => :plan
  },
  :user => {
    :name                  => :user_name,
    :email                 => :email,
    :password              => :password,
    :password_confirmation => :password_confirmation,
  }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Signup

Returns a new instance of Signup.



32
33
34
35
36
37
# File 'app/models/signup.rb', line 32

def initialize(attributes = {})
  attributes.each do |attribute, value|
    send(:"#{attribute}=", value)
  end
  @check_password = true
end

Instance Attribute Details

#account_nameObject

Returns the value of attribute account_name.



28
29
30
# File 'app/models/signup.rb', line 28

def 
  @account_name
end

#billing_emailObject

Returns the value of attribute billing_email.



28
29
30
# File 'app/models/signup.rb', line 28

def billing_email
  @billing_email
end

#card_numberObject

Returns the value of attribute card_number.



28
29
30
# File 'app/models/signup.rb', line 28

def card_number
  @card_number
end

#cardholder_nameObject

Returns the value of attribute cardholder_name.



28
29
30
# File 'app/models/signup.rb', line 28

def cardholder_name
  @cardholder_name
end

#emailObject

Returns the value of attribute email.



28
29
30
# File 'app/models/signup.rb', line 28

def email
  @email
end

#expiration_monthObject

Returns the value of attribute expiration_month.



28
29
30
# File 'app/models/signup.rb', line 28

def expiration_month
  @expiration_month
end

#expiration_yearObject

Returns the value of attribute expiration_year.



28
29
30
# File 'app/models/signup.rb', line 28

def expiration_year
  @expiration_year
end

#keywordObject

Returns the value of attribute keyword.



28
29
30
# File 'app/models/signup.rb', line 28

def keyword
  @keyword
end

#passwordObject

Returns the value of attribute password.



28
29
30
# File 'app/models/signup.rb', line 28

def password
  @password
end

#password_confirmationObject

Returns the value of attribute password_confirmation.



28
29
30
# File 'app/models/signup.rb', line 28

def password_confirmation
  @password_confirmation
end

#planObject

Returns the value of attribute plan.



28
29
30
# File 'app/models/signup.rb', line 28

def plan
  @plan
end

#user_nameObject

Returns the value of attribute user_name.



28
29
30
# File 'app/models/signup.rb', line 28

def user_name
  @user_name
end

#verification_codeObject

Returns the value of attribute verification_code.



28
29
30
# File 'app/models/signup.rb', line 28

def verification_code
  @verification_code
end

Instance Method Details

#accountObject



62
63
64
# File 'app/models/signup.rb', line 62

def 
  @account ||= Account.new
end

#email_confirmed?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'app/models/signup.rb', line 95

def email_confirmed?
  user.email_confirmed?
end

#existing_userObject



79
80
81
# File 'app/models/signup.rb', line 79

def existing_user
  @existing_user ||= User.find_by_email(email)
end

#membershipObject



83
84
85
86
87
# File 'app/models/signup.rb', line 83

def membership
  @membership ||= Membership.new(:user    => user,
                                 :account => ,
                                 :admin   => true)
end

#new_userObject



75
76
77
# File 'app/models/signup.rb', line 75

def new_user
  @new_user ||= User.new
end

#persisted?Boolean

used by ActiveModel

Returns:

  • (Boolean)


40
41
42
# File 'app/models/signup.rb', line 40

def persisted?
  false
end

#saveObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/signup.rb', line 44

def save
  delegate_attributes_for(:account)
  delegate_attributes_for(:user) unless existing_user

  if valid?
    begin
      save!
      true
    rescue ActiveRecord::RecordNotSaved
      delegate_errors_for(:account)
      delegate_errors_for(:user)
      false
    end
  else
    false
  end
end

#userObject



66
67
68
# File 'app/models/signup.rb', line 66

def user
  existing_user || new_user
end

#user=(signed_in_user) ⇒ Object



70
71
72
73
# File 'app/models/signup.rb', line 70

def user=(signed_in_user)
  @check_password = false
  @existing_user  = signed_in_user
end

#valid?Boolean

Returns:

  • (Boolean)


89
90
91
92
93
# File 'app/models/signup.rb', line 89

def valid?
  errors.clear
  validate
  errors.empty?
end