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)


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

def can_be_deleted?
  pending?
end

#can_be_edited?Boolean

Permission Methods


Returns:

  • (Boolean)


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

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"


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_nameObject

  • 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

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"


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

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"


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

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