Sha256: 3e08161159051804ec6d1ce2b14a18b2d6de5de14bc58a93bb7c1085eb4922cc

Contents?: true

Size: 721 Bytes

Versions: 55

Compression:

Stored size: 721 Bytes

Contents

require "securerandom"

# Associates a Participant with an action on a date and provides an obfuscated
# token representation.
class ParticipantToken < ActiveRecord::Base
  TYPES = %w( phq9 wai )
  TOKEN_LENGTH = 10

  belongs_to :participant

  validates :participant, :token, :token_type, presence: true
  validates :token, uniqueness: { scope: :participant_id }
  validates :token_type, presence: { in: TYPES }

  before_validation :make_token

  def to_s
    token
  end

  def others_on_this_day
    self.class.where(participant_id: participant_id,
                     release_date: release_date)
      .where.not(id: id)
  end

  private

  def make_token
    self.token = SecureRandom.hex(TOKEN_LENGTH)
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
think_feel_do_engine-3.19.9 app/models/participant_token.rb
think_feel_do_engine-3.19.8 app/models/participant_token.rb
think_feel_do_engine-3.19.7 app/models/participant_token.rb
think_feel_do_engine-3.19.6 app/models/participant_token.rb
think_feel_do_engine-3.19.5 app/models/participant_token.rb
think_feel_do_engine-3.19.4 app/models/participant_token.rb
think_feel_do_engine-3.19.3 app/models/participant_token.rb
think_feel_do_engine-3.19.2 app/models/participant_token.rb
think_feel_do_engine-3.19.1 app/models/participant_token.rb
think_feel_do_engine-3.19.0 app/models/participant_token.rb
think_feel_do_engine-3.18.0 app/models/participant_token.rb
think_feel_do_engine-3.17.2 app/models/participant_token.rb
think_feel_do_engine-3.17.1 app/models/participant_token.rb
think_feel_do_engine-3.17.0 app/models/participant_token.rb
think_feel_do_engine-3.16.3 app/models/participant_token.rb
think_feel_do_engine-3.16.2 app/models/participant_token.rb
think_feel_do_engine-3.16.1 app/models/participant_token.rb
think_feel_do_engine-3.15.7 app/models/participant_token.rb
think_feel_do_engine-3.16.0 app/models/participant_token.rb
think_feel_do_engine-3.15.6 app/models/participant_token.rb