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"
- SUSPENDED =
"suspended"
- DELETED =
"deleted"
- STATUS =
{ PENDING => "Pending", VERIFIED => "Verified", SUSPENDED => "Suspended", DELETED => "Deleted" }
- STATUS_REVERSE =
{ "Pending" => PENDING, "Verified" => VERIFIED, "Suspended" => SUSPENDED, "Deleted" => DELETED }
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 ——————.
-
#delete! ⇒ Object
change the status to :deleted Return the status == Examples >>> registration.delete! => “deleted”.
-
#deleted? ⇒ Boolean
-
Return true if the user is deleted, else false.
-
-
#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.
-
-
#suspend! ⇒ Object
change the status to :suspended Return the status == Examples >>> registration.suspend! => “suspended”.
-
#suspended? ⇒ Boolean
-
Return true if the user is suspended, 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.
63 64 65 66 67 68 69 70 |
# File 'app/models/registration.rb', line 63 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
150 151 152 |
# File 'app/models/registration.rb', line 150 def can_be_deleted? pending? end |
#can_be_edited? ⇒ Boolean
Permission Methods
146 147 148 |
# File 'app/models/registration.rb', line 146 def can_be_edited? pending? end |
#delete! ⇒ Object
change the status to :deleted Return the status
Examples
>>> registration.delete!
=> "deleted"
139 140 141 |
# File 'app/models/registration.rb', line 139 def delete! self.update_attribute(:status, DELETED) end |
#deleted? ⇒ Boolean
-
Return true if the user is deleted, else false.
Examples
>>> registration.deleted?
=> true
103 104 105 |
# File 'app/models/registration.rb', line 103 def deleted? (status == DELETED) end |
#display_location ⇒ Object
-
Return city, country or just country if there is no city
Examples
>>> registration.display_location
=> "Dubai, United Arab Emirates"
169 170 171 |
# File 'app/models/registration.rb', line 169 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"
161 162 163 |
# File 'app/models/registration.rb', line 161 def display_name "#{self.dialing_prefix} #{self.mobile_number}" end |
#pending! ⇒ Object
change the status to :verified Return the status
Examples
>>> registration.pending!
=> "pending"
112 113 114 |
# File 'app/models/registration.rb', line 112 def pending! self.update_attribute(:status, PENDING) end |
#pending? ⇒ Boolean
-
Return true if the user is pending, else false.
Examples
>>> registration.pending?
=> true
79 80 81 |
# File 'app/models/registration.rb', line 79 def pending? (status == PENDING) end |
#suspend! ⇒ Object
change the status to :suspended Return the status
Examples
>>> registration.suspend!
=> "suspended"
130 131 132 |
# File 'app/models/registration.rb', line 130 def suspend! self.update_attribute(:status, SUSPENDED) end |
#suspended? ⇒ Boolean
-
Return true if the user is suspended, else false.
Examples
>>> registration.suspended?
=> true
95 96 97 |
# File 'app/models/registration.rb', line 95 def suspended? (status == SUSPENDED) end |
#verified? ⇒ Boolean
-
Return true if the user is not verified, else false.
Examples
>>> registration.verified?
=> true
87 88 89 |
# File 'app/models/registration.rb', line 87 def verified? (status == VERIFIED) end |
#verify! ⇒ Object
change the status to :verified Return the status
Examples
>>> registration.verify!
=> "verified"
121 122 123 |
# File 'app/models/registration.rb', line 121 def verify! self.update_attribute(:status, VERIFIED) end |