Sha256: cf7e3e31af845d86da080c9f571950bc13a362b8a9fbe9aa0c28d19f9676ff0e

Contents?: true

Size: 1.87 KB

Versions: 15

Compression:

Stored size: 1.87 KB

Contents

module TestTrack::Identity
  extend ActiveSupport::Concern

  module ClassMethods
    # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
    def test_track_identifier(identifier_type, identifier_value_method)
      instance_methods = Module.new
      include instance_methods

      instance_methods.module_eval do
        define_method :test_track_ab do |*args|
          discriminator = TestTrack::IdentitySessionDiscriminator.new(self)

          if discriminator.participate_in_online_session?
            discriminator.controller.send(:test_track_visitor).ab(*args)
          else
            identifier_value = send(identifier_value_method)
            TestTrack::OfflineSession.with_visitor_for(identifier_type, identifier_value) do |v|
              v.ab(*args)
            end
          end
        end

        define_method :test_track_vary do |*args, &block|
          discriminator = TestTrack::IdentitySessionDiscriminator.new(self)

          if discriminator.participate_in_online_session?
            discriminator.controller.send(:test_track_visitor).vary(*args, &block)
          else
            identifier_value = send(identifier_value_method)
            TestTrack::OfflineSession.with_visitor_for(identifier_type, identifier_value) do |v|
              v.vary(*args, &block)
            end
          end
        end

        define_method :test_track_visitor_id do
          discriminator = TestTrack::IdentitySessionDiscriminator.new(self)

          if discriminator.participate_in_online_session?
            discriminator.controller.send(:test_track_visitor).id
          else
            identifier_value = send(identifier_value_method)
            TestTrack::OfflineSession.with_visitor_for(identifier_type, identifier_value) do |v|
              v.id
            end
          end
        end
      end
    end
    # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
test_track_rails_client-0.9.14 app/models/concerns/test_track/identity.rb
test_track_rails_client-0.9.13 app/models/concerns/test_track/identity.rb
test_track_rails_client-0.9.12 app/models/concerns/test_track/identity.rb
test_track_rails_client-0.9.11 app/models/concerns/test_track/identity.rb
test_track_rails_client-0.9.10 app/models/concerns/test_track/identity.rb
test_track_rails_client-0.9.9 app/models/concerns/test_track/identity.rb
test_track_rails_client-0.9.8 app/models/concerns/test_track/identity.rb
test_track_rails_client-0.9.7 app/models/concerns/test_track/identity.rb
test_track_rails_client-0.9.6 app/models/concerns/test_track/identity.rb
test_track_rails_client-0.9.5 app/models/concerns/test_track/identity.rb
test_track_rails_client-0.9.4 app/models/concerns/test_track/identity.rb
test_track_rails_client-0.9.3 app/models/concerns/test_track/identity.rb
test_track_rails_client-0.9.2 app/models/concerns/test_track/identity.rb
test_track_rails_client-0.9.1 app/models/concerns/test_track/identity.rb
test_track_rails_client-0.9.0 app/models/concerns/test_track/identity.rb