Sha256: e716a049e03c561427765af8508cdef6766fd36418f08fc120a0a5748eb296ce

Contents?: true

Size: 1.65 KB

Versions: 4

Compression:

Stored size: 1.65 KB

Contents

module TestTrack::Identity
  extend ActiveSupport::Concern

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

      instance_methods.module_eval do
        define_method :test_track_identifier_type do
          identifier_type
        end

        define_method :test_track_identifier_value do
          send(identifier_value_method)
        end

        define_method :test_track_ab do |*args|
          discriminator = TestTrack::IdentitySessionDiscriminator.new(self)
          discriminator.with_visitor do |v|
            v.ab(*args)
          end
        end

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

        define_method :test_track_visitor_id do
          discriminator = TestTrack::IdentitySessionDiscriminator.new(self)
          discriminator.with_visitor do |v|
            v.id
          end
        end

        define_method :test_track_sign_up! do
          discriminator = TestTrack::IdentitySessionDiscriminator.new(self)
          discriminator.with_session do |session|
            session.sign_up! self
          end
        end

        define_method :test_track_log_in! do |opts = {}|
          discriminator = TestTrack::IdentitySessionDiscriminator.new(self)
          discriminator.with_session do |session|
            session.log_in! self, opts
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
test_track_rails_client-3.0.1 app/models/concerns/test_track/identity.rb
test_track_rails_client-3.0.0 app/models/concerns/test_track/identity.rb
test_track_rails_client-2.0.0 app/models/concerns/test_track/identity.rb
test_track_rails_client-1.3.0 app/models/concerns/test_track/identity.rb