lib/field_test/participant.rb in field_test-0.2.4 vs lib/field_test/participant.rb in field_test-0.3.0
- old
+ new
@@ -1,7 +1,38 @@
module FieldTest
class Participant
- def self.standardize(participants)
- Array(participants).map { |v| v.respond_to?(:model_name) ? "#{v.model_name.name}:#{v.id}" : v.to_s }
+ attr_reader :type, :id
+
+ def initialize(object)
+ if object.is_a?(FieldTest::Participant)
+ @type = object.type
+ @id = object.id
+ elsif object.respond_to?(:model_name)
+ @type = object.model_name.name
+ @id = object.id.to_s
+ else
+ @id = object.to_s
+ end
+ end
+
+ def participant
+ [type, id].compact.join(":")
+ end
+
+ def where_values
+ if FieldTest.legacy_participants
+ {
+ participant: participant
+ }
+ else
+ {
+ participant_type: type,
+ participant_id: id
+ }
+ end
+ end
+
+ def self.standardize(participants, options = {})
+ Array(options[:participant] || participants).compact.map { |v| FieldTest::Participant.new(v) }
end
end
end