Sha256: d1afb3d171b1978baec8d496faeb53bcb5ad738f32a5e4f251d98347a4df6910

Contents?: true

Size: 1.49 KB

Versions: 20

Compression:

Stored size: 1.49 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, :empty?

        def initialize(adapter)
          @adapter = case adapter.class.to_s
                     when 'SplitIoClient::Cache::Adapters::MemoryAdapter'
                       Repositories::Impressions::MemoryRepository.new(adapter)
                     when 'SplitIoClient::Cache::Adapters::RedisAdapter'
                       Repositories::Impressions::RedisRepository.new(adapter)
                     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: "#{SplitIoClient.configuration.language}-#{SplitIoClient.configuration.version}",
            i: SplitIoClient.configuration.machine_ip,
            n: SplitIoClient.configuration.machine_name
          }
        end

        def applied_rule(label)
          SplitIoClient.configuration.labels_enabled ? label : nil
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
splitclient-rb-6.1.0-java lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-6.1.0 lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-6.1.0.pre.rc2-java lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-6.1.0.pre.rc2 lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-6.1.0.pre.rc1-java lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-6.1.0.pre.rc1 lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-6.0.1-java lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-6.0.1 lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-6.0.1.pre.rc2-java lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-6.0.1.pre.rc2 lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-6.0.1.pre.rc1-java lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-6.0.1.pre.rc1 lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-6.0.0-java lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-6.0.0 lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-5.1.3.pre.rc4-java lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-5.1.3.pre.rc4 lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-5.1.3.pre.rc3-java lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-5.1.3.pre.rc3 lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-5.1.3.pre.rc2-java lib/splitclient-rb/cache/repositories/impressions_repository.rb
splitclient-rb-5.1.3.pre.rc2 lib/splitclient-rb/cache/repositories/impressions_repository.rb