Sha256: fd8eae0b2d15948219f74fd75a842642121cbdc148d3b84575cec4671b57499c

Contents?: true

Size: 1.44 KB

Versions: 8

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module SplitIoClient
  module Cache
    module Repositories
      # Repository which forwards impressions interface to the selected adapter
      class ImpressionsRepository < Repository
        extend Forwardable
        def_delegators :@adapter, :add, :add_bulk, :batch, :clear, :empty?

        def initialize(config)
          super(config)
          @adapter = case @config.impressions_adapter.class.to_s
                     when 'SplitIoClient::Cache::Adapters::MemoryAdapter'
                       Repositories::Impressions::MemoryRepository.new(@config)
                     when 'SplitIoClient::Cache::Adapters::RedisAdapter'
                       Repositories::Impressions::RedisRepository.new(@config)
                     end
        end

        protected

        def impression_data(matching_key, bucketing_key, split_name, treatment, timestamp)
          {
            k: matching_key,
            b: bucketing_key,
            f: split_name,
            t: treatment[:treatment],
            r: applied_rule(treatment[:label]),
            c: treatment[:change_number],
            m: timestamp
          }
        end

        def metadata
          {
            s: "#{@config.language}-#{@config.version}",
            i: @config.machine_ip,
            n: @config.machine_name
          }
        end

        def applied_rule(label)
          @config.labels_enabled ? label : nil
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
splitclient-rb-7.0.0-java lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-7.0.0 lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-7.0.0.pre.rc3-java lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-7.0.0.pre.rc3 lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-7.0.0.pre.rc2-java lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-7.0.0.pre.rc2 lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-7.0.0.pre.rc1-java lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-7.0.0.pre.rc1 lib/splitclient-rb/cache/repositories/impressions_repository.rb