Class: Vanity::Adapters::ActiveRecordAdapter::VanityParticipant

Inherits:
VanityRecord
  • Object
show all
Defined in:
lib/vanity/adapters/active_record_adapter.rb

Overview

Participant model

Class Method Summary collapse

Class Method Details

.retrieve(experiment, identity, create = true, update_with = nil) ⇒ Object

Finds the participant by experiment and identity. If create is true then it will create the participant if not found. If a hash is passed then this will be passed to create if creating, or will be used to update the found participant.



74
75
76
77
78
79
80
81
# File 'lib/vanity/adapters/active_record_adapter.rb', line 74

def self.retrieve(experiment, identity, create = true, update_with = nil)
  if record = VanityParticipant.first(:conditions=>{ :experiment_id=>experiment.to_s, :identity=>identity.to_s })
    record.update_attributes(update_with) if update_with
  elsif create
    record = VanityParticipant.create({ :experiment_id=>experiment.to_s, :identity=>identity }.merge(update_with || {}))
  end
  record
end