class SnowmanIO::User

Public Instance Methods

as_json(options = {}) click to toggle source
Calls superclass method
# File lib/snowman-io/models/user.rb, line 65
def as_json(options = {})
  super(options.merge(except: ["authentication_token", "password_digest", "invite_token"])).tap { |o|
    o["id"] = o.delete("_id").to_s
    o["following_ids"] = followings.map(&:id).map(&:to_s)
    o["follower_ids"] = followers.map(&:id).map(&:to_s)
  }
end
follow!(other) click to toggle source
# File lib/snowman-io/models/user.rb, line 34
def follow!(other)
  following_joins.find_or_create_by!(target_id: other.id)
end
followers() click to toggle source
# File lib/snowman-io/models/user.rb, line 30
def followers
  follower_joins.map(&:user)
end
followings() click to toggle source
# File lib/snowman-io/models/user.rb, line 26
def followings
  following_joins.map(&:target)
end
invite!(by) click to toggle source
# File lib/snowman-io/models/user.rb, line 42
def invite!(by)
  if self.invite_token.blank?
    self.invite_token = generate_token(:invite_token)
  end
  self.invite_send_count += 1
  save!

  SnowMailer.send_invite(self, Setting.get(SnowmanIO::BASE_URL_KEY), by).deliver_now
end
restore_password!() click to toggle source
# File lib/snowman-io/models/user.rb, line 52
def restore_password!
  if self.restore_pass_token.blank?
    self.restore_pass_token = generate_token(:restore_pass_token)
  end
  save!

  SnowMailer.restore_password(self, Setting.get(SnowmanIO::BASE_URL_KEY)).deliver_now
end
unfollow!(other) click to toggle source
# File lib/snowman-io/models/user.rb, line 38
def unfollow!(other)
  following_joins.where(target_id: other.id).destroy_all
end