Sha256: d1e3cc5a8b8a4f8bb3fde39a4be46d7ea98e671d0fe1d337025f4447f47a371c

Contents?: true

Size: 781 Bytes

Versions: 13

Compression:

Stored size: 781 Bytes

Contents

module FieldTest
  class Participant
    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(participant)
      Array(participant).compact.map { |v| FieldTest::Participant.new(v) }
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
field_test-0.7.0 lib/field_test/participant.rb
field_test-0.6.1 lib/field_test/participant.rb
field_test-0.6.0 lib/field_test/participant.rb
field_test-0.5.5 lib/field_test/participant.rb
field_test-0.5.4 lib/field_test/participant.rb
field_test-0.5.3 lib/field_test/participant.rb
field_test-0.5.2 lib/field_test/participant.rb
field_test-0.5.1 lib/field_test/participant.rb
field_test-0.5.0 lib/field_test/participant.rb
field_test-0.4.1 lib/field_test/participant.rb
field_test-0.4.0 lib/field_test/participant.rb
field_test-0.3.2 lib/field_test/participant.rb
field_test-0.3.1 lib/field_test/participant.rb