Module: TestTrack::Identity::ClassMethods

Defined in:
app/models/concerns/test_track/identity.rb

Instance Method Summary collapse

Instance Method Details

#test_track_identifier(identifier_type, identifier_value_method) ⇒ Object

rubocop:disable Metrics/MethodLength, Metrics/AbcSize



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/concerns/test_track/identity.rb', line 5

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|
      locator = TestTrack::IdentitySessionLocator.new(self)
      locator.with_visitor do |v|
        v.ab(*args)
      end
    end

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

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

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

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