Class: Registration
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Registration
- Defined in:
- app/models/registration.rb
Constant Summary collapse
- EXCLUDED_JSON_ATTRIBUTES =
Constants
[:created_at, :updated_at]
- PENDING =
"pending"- VERIFIED =
"verified"- STATUS =
{ PENDING => "Pending", VERIFIED => "Verified" }
- STATUS_REVERSE =
{ "Pending" => PENDING, "Verified" => VERIFIED }
Instance Method Summary collapse
-
#as_json(options = {}) ⇒ Object
Exclude some attributes info from json output.
- #can_be_deleted? ⇒ Boolean
-
#can_be_edited? ⇒ Boolean
Permission Methods ——————.
-
#display_location ⇒ Object
-
Return city, country or just country if there is no city == Examples >>> registration.display_location => “Dubai, United Arab Emirates”.
-
-
#display_name ⇒ Object
-
Return mobile number with dialling prefix == Examples >>> registration.display_name => “+919880123456”.
-
-
#pending! ⇒ Object
change the status to :verified Return the status == Examples >>> registration.pending! => “pending”.
-
#pending? ⇒ Boolean
-
Return true if the user is pending, else false.
-
-
#verified? ⇒ Boolean
-
Return true if the user is not verified, else false.
-
-
#verify! ⇒ Object
change the status to :verified Return the status == Examples >>> registration.verify! => “verified”.
Instance Method Details
#as_json(options = {}) ⇒ Object
Exclude some attributes info from json output.
52 53 54 55 56 57 58 59 |
# File 'app/models/registration.rb', line 52 def as_json(={}) [:except] ||= EXCLUDED_JSON_ATTRIBUTES #options[:include] ||= [] #options[:methods] = [] #options[:methods] << :profile_image json = super() Hash[*json.map{|k, v| [k, v || ""]}.flatten] end |
#can_be_deleted? ⇒ Boolean
105 106 107 |
# File 'app/models/registration.rb', line 105 def can_be_deleted? pending? end |
#can_be_edited? ⇒ Boolean
Permission Methods
101 102 103 |
# File 'app/models/registration.rb', line 101 def can_be_edited? pending? end |
#display_location ⇒ Object
-
Return city, country or just country if there is no city
Examples
>>> registration.display_location
=> "Dubai, United Arab Emirates"
124 125 126 |
# File 'app/models/registration.rb', line 124 def display_location [self.city.try(:name), self.country.try(:name)].compact.join(",") end |
#display_name ⇒ Object
-
Return mobile number with dialling prefix
Examples
>>> registration.display_name
=> "+919880123456"
116 117 118 |
# File 'app/models/registration.rb', line 116 def display_name "#{self.dialing_prefix} #{self.mobile_number}" end |
#pending! ⇒ Object
change the status to :verified Return the status
Examples
>>> registration.pending!
=> "pending"
85 86 87 |
# File 'app/models/registration.rb', line 85 def pending! self.update_attribute(:status, PENDING) end |
#pending? ⇒ Boolean
-
Return true if the user is pending, else false.
Examples
>>> registration.pending?
=> true
68 69 70 |
# File 'app/models/registration.rb', line 68 def pending? (status == PENDING) end |
#verified? ⇒ Boolean
-
Return true if the user is not verified, else false.
Examples
>>> registration.verified?
=> true
76 77 78 |
# File 'app/models/registration.rb', line 76 def verified? (status == VERIFIED) end |
#verify! ⇒ Object
change the status to :verified Return the status
Examples
>>> registration.verify!
=> "verified"
94 95 96 |
# File 'app/models/registration.rb', line 94 def verify! self.update_attribute(:status, VERIFIED) end |