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.



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

def self.retrieve(experiment, identity, create = true, update_with = nil)
  exp = VanityExperiment.retrieve(experiment)
  raise "no experiment found #{experiment}" unless exp
  if record = exp.vanity_participants.first(:conditions=>{ :identity=>identity })
    record.update_attributes(update_with) if update_with
  elsif create
    record = VanityParticipant.create({ :vanity_experiment_id=>exp.id, :identity=>identity }.merge(update_with || {}))
  end
  record
end