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"
STATUS =
{ 
  PENDING => "Pending", 
  VERIFIED => "Verified",
  SUSPENDED => "Suspended"
}
STATUS_REVERSE =
{ 
  "Pending" => PENDING,
  "Verified" => VERIFIED,
  "Suspended" => SUSPENDED
}

Instance Method Summary collapse

Instance Method Details

#as_json(options = {}) ⇒ Object

Exclude some attributes info from json output.



58
59
60
61
62
63
64
65
# File 'app/models/registration.rb', line 58

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



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

def can_be_deleted?
  pending?
end

#can_be_edited?Boolean

Permission Methods




127
128
129
# File 'app/models/registration.rb', line 127

def can_be_edited?
  pending?
end

#display_locationObject

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

Examples

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


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

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"


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

def display_name
  "#{self.dialing_prefix} #{self.mobile_number}"
end

#pending!Object

change the status to :verified Return the status

Examples

>>> registration.pending!
=> "pending"


99
100
101
102
# File 'app/models/registration.rb', line 99

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


74
75
76
# File 'app/models/registration.rb', line 74

def pending?
  (status == PENDING)
end

#suspend!Object

change the status to :suspended Return the status

Examples

>>> registration.suspend!
=> "suspended"


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

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


90
91
92
# File 'app/models/registration.rb', line 90

def suspended?
  (status == SUSPENDED)
end

#verified?Boolean

  • Return true if the user is not verified, else false.

Examples

>>> registration.verified?
=> true


82
83
84
# File 'app/models/registration.rb', line 82

def verified?
  (status == VERIFIED)
end

#verify!Object

change the status to :verified Return the status

Examples

>>> registration.verify!
=> "verified"


109
110
111
112
# File 'app/models/registration.rb', line 109

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