Class: Registration

Inherits:
ApplicationRecord
  • Object
show all
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

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(options={})
  options[:except] ||= EXCLUDED_JSON_ATTRIBUTES
  #options[:include] ||= []
  #options[:methods] = []
  #options[:methods] << :profile_image
  json = super(options)
  Hash[*json.map{|k, v| [k, v || ""]}.flatten]
end

#can_be_deleted?Boolean

Returns:

  • (Boolean)


154
155
156
# File 'app/models/registration.rb', line 154

def can_be_deleted?
  pending?
end

#can_be_edited?Boolean

Permission Methods


Returns:

  • (Boolean)


150
151
152
# File 'app/models/registration.rb', line 150

def can_be_edited?
  pending?
end

#delete!Object

change the status to :deleted Return the status

Examples

>>> registration.delete!
=> "deleted"


142
143
144
145
# File 'app/models/registration.rb', line 142

def delete!
  self.update_attribute(:status, DELETED)
  self.user.update_attribute(:status, DELETED) if self.user
end

#deleted?Boolean

  • Return true if the user is deleted, else false.

Examples

>>> registration.deleted?
=> true

Returns:

  • (Boolean)


103
104
105
# File 'app/models/registration.rb', line 103

def deleted?
  (status == DELETED)
end

#display_locationObject

  • Return city, country or just country if there is no city

Examples

>>> registration.display_location
=> "Dubai, United Arab Emirates"


173
174
175
# File 'app/models/registration.rb', line 173

def display_location
  [self.city.try(:name), self.country.try(:name)].compact.join(",")
end

#display_nameObject

  • Return mobile number with dialling prefix

Examples

>>> registration.display_name
=> "+919880123456"


165
166
167
# File 'app/models/registration.rb', line 165

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
115
# File 'app/models/registration.rb', line 112

def pending!
  self.update_attribute(:status, PENDING)
  self.user.update_attribute(:status, PENDING) if self.user
end

#pending?Boolean

  • Return true if the user is pending, else false.

Examples

>>> registration.pending?
=> true

Returns:

  • (Boolean)


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"


132
133
134
135
# File 'app/models/registration.rb', line 132

def suspend!
  self.update_attribute(:status, SUSPENDED)
  self.user.update_attribute(:status, SUSPENDED) if self.user
end

#suspended?Boolean

  • Return true if the user is suspended, else false.

Examples

>>> registration.suspended?
=> true

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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"


122
123
124
125
# File 'app/models/registration.rb', line 122

def verify!
  self.update_attribute(:status, VERIFIED)
  self.user.update_attribute(:status, VERIFIED) if self.user
end