Class: Signup
- Inherits:
-
Object
- Object
- Signup
- 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 => { :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, :street_address => :street_address, :extended_address => :extended_address, :locality => :locality, :region => :region, :postal_code => :postal_code, :country_name => :country_name }, :user => { :email => :email, :password => :password, } }.freeze
Instance Attribute Summary collapse
-
#billing_email ⇒ Object
Returns the value of attribute billing_email.
-
#card_number ⇒ Object
Returns the value of attribute card_number.
-
#cardholder_name ⇒ Object
Returns the value of attribute cardholder_name.
-
#country_name ⇒ Object
Returns the value of attribute country_name.
-
#coupon ⇒ Object
Returns the value of attribute coupon.
-
#email ⇒ Object
Returns the value of attribute email.
-
#expiration_month ⇒ Object
Returns the value of attribute expiration_month.
-
#expiration_year ⇒ Object
Returns the value of attribute expiration_year.
-
#extended_address ⇒ Object
Returns the value of attribute extended_address.
-
#locality ⇒ Object
Returns the value of attribute locality.
-
#password ⇒ Object
Returns the value of attribute password.
-
#plan ⇒ Object
Returns the value of attribute plan.
-
#postal_code ⇒ Object
Returns the value of attribute postal_code.
-
#quick ⇒ Object
Returns the value of attribute quick.
-
#region ⇒ Object
Returns the value of attribute region.
-
#street_address ⇒ Object
Returns the value of attribute street_address.
-
#verification_code ⇒ Object
Returns the value of attribute verification_code.
Instance Method Summary collapse
- #account ⇒ Object
- #existing_user ⇒ Object
-
#initialize(attributes = {}) ⇒ Signup
constructor
A new instance of Signup.
- #membership ⇒ Object
- #new_user ⇒ Object
-
#persisted? ⇒ Boolean
used by ActiveModel.
- #save ⇒ Object
- #user ⇒ Object
- #user=(signed_in_user) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ Signup
Returns a new instance of Signup.
35 36 37 38 39 40 41 42 |
# File 'app/models/signup.rb', line 35 def initialize(attributes = {}) if attributes attributes.each do |attribute, value| send(:"#{attribute}=", value) end end @check_password = true end |
Instance Attribute Details
#billing_email ⇒ Object
Returns the value of attribute billing_email.
30 31 32 |
# File 'app/models/signup.rb', line 30 def billing_email @billing_email end |
#card_number ⇒ Object
Returns the value of attribute card_number.
30 31 32 |
# File 'app/models/signup.rb', line 30 def card_number @card_number end |
#cardholder_name ⇒ Object
Returns the value of attribute cardholder_name.
30 31 32 |
# File 'app/models/signup.rb', line 30 def cardholder_name @cardholder_name end |
#country_name ⇒ Object
Returns the value of attribute country_name.
30 31 32 |
# File 'app/models/signup.rb', line 30 def country_name @country_name end |
#coupon ⇒ Object
Returns the value of attribute coupon.
30 31 32 |
# File 'app/models/signup.rb', line 30 def coupon @coupon end |
#email ⇒ Object
Returns the value of attribute email.
30 31 32 |
# File 'app/models/signup.rb', line 30 def email @email end |
#expiration_month ⇒ Object
Returns the value of attribute expiration_month.
30 31 32 |
# File 'app/models/signup.rb', line 30 def expiration_month @expiration_month end |
#expiration_year ⇒ Object
Returns the value of attribute expiration_year.
30 31 32 |
# File 'app/models/signup.rb', line 30 def expiration_year @expiration_year end |
#extended_address ⇒ Object
Returns the value of attribute extended_address.
30 31 32 |
# File 'app/models/signup.rb', line 30 def extended_address @extended_address end |
#locality ⇒ Object
Returns the value of attribute locality.
30 31 32 |
# File 'app/models/signup.rb', line 30 def locality @locality end |
#password ⇒ Object
Returns the value of attribute password.
30 31 32 |
# File 'app/models/signup.rb', line 30 def password @password end |
#plan ⇒ Object
Returns the value of attribute plan.
30 31 32 |
# File 'app/models/signup.rb', line 30 def plan @plan end |
#postal_code ⇒ Object
Returns the value of attribute postal_code.
30 31 32 |
# File 'app/models/signup.rb', line 30 def postal_code @postal_code end |
#quick ⇒ Object
Returns the value of attribute quick.
30 31 32 |
# File 'app/models/signup.rb', line 30 def quick @quick end |
#region ⇒ Object
Returns the value of attribute region.
30 31 32 |
# File 'app/models/signup.rb', line 30 def region @region end |
#street_address ⇒ Object
Returns the value of attribute street_address.
30 31 32 |
# File 'app/models/signup.rb', line 30 def street_address @street_address end |
#verification_code ⇒ Object
Returns the value of attribute verification_code.
30 31 32 |
# File 'app/models/signup.rb', line 30 def verification_code @verification_code end |
Instance Method Details
#account ⇒ Object
72 73 74 |
# File 'app/models/signup.rb', line 72 def account @account ||= existing_account_in_quick_mode || Account.new end |
#existing_user ⇒ Object
89 90 91 |
# File 'app/models/signup.rb', line 89 def existing_user @existing_user ||= User.find_by_email(email) end |
#membership ⇒ Object
93 94 95 96 97 |
# File 'app/models/signup.rb', line 93 def membership @membership ||= Membership.new(:user => user, :account => account, :admin => true) end |
#new_user ⇒ Object
85 86 87 |
# File 'app/models/signup.rb', line 85 def new_user @new_user ||= User.new end |
#persisted? ⇒ Boolean
used by ActiveModel
45 46 47 |
# File 'app/models/signup.rb', line 45 def persisted? false end |
#save ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/signup.rb', line 49 def save delegate_attributes_for(:account) populate_additional_account_fields if !existing_user delegate_attributes_for(:user) populate_additional_user_fields end if valid? begin save! true rescue ActiveRecord::RecordNotSaved delegate_errors_for(:account) delegate_errors_for(:user) false end else false end end |
#user ⇒ Object
76 77 78 |
# File 'app/models/signup.rb', line 76 def user existing_user || new_user end |
#user=(signed_in_user) ⇒ Object
80 81 82 83 |
# File 'app/models/signup.rb', line 80 def user=(signed_in_user) @check_password = false @existing_user = signed_in_user end |
#valid? ⇒ Boolean
99 100 101 102 103 |
# File 'app/models/signup.rb', line 99 def valid? errors.clear validate errors.empty? end |