<commit_before>require 'yaml'
require 'active_model'
require 'multi_json'
require 'pushr/version'
require 'pushr/configuration'
require 'pushr/message'
require 'pushr/feedback'
require 'pushr/redis_connection'

module Pushr

  module Core
    NAME = 'Pushr'
    DEFAULTS = {}

    attr_writer :options

    @@external_id_tag = 'external_id'

    def self.external_id_tag=(value)
      @@external_id_tag = value
    end

    def self.external_id_tag
      @@external_id_tag
    end

    def self.options
      @options ||= DEFAULTS.dup
    end

    ##
    # Configuration for Pushr, use like:
    #
    #   Pushr.configure do |config|
    #     config.redis = { :namespace => 'myapp', :size => 1, :url => 'redis://myhost:8877/mydb' }
    #   end
    def self.configure
      yield self
    end

    def self.redis(&block)
      fail ArgumentError, 'requires a block' unless block
      @redis ||= Pushr::RedisConnection.create
      @redis.with(&block)
    end

    def self.redis=(hash)
      if hash.is_a?(Hash)
        @redis = RedisConnection.create(hash)
        options[:namespace] ||= hash[:namespace]
      elsif hash.is_a?(ConnectionPool)
        @redis = hash
      else
        fail ArgumentError, 'redis= requires a Hash or ConnectionPool'
      end
    end

    # instruments with a block
    def self.instrument(name, payload = {}, &block)
      ActiveSupport::Notifications.instrument(name, payload) do
        yield
      end
    end
  end
end<commit_msg>moved external_id_tag to options variable<commit_after>require 'yaml'
require 'active_model'
require 'multi_json'
require 'pushr/version'
require 'pushr/configuration'
require 'pushr/message'
require 'pushr/feedback'
require 'pushr/redis_connection'

module Pushr
  module Core
    NAME = 'Pushr'
    DEFAULTS = { external_id_tag: 'external_id' }

    attr_writer :options

    def self.options
      @options ||= DEFAULTS.dup
    end

    ##
    # Configuration for Pushr, use like:
    #
    #   Pushr.configure do |config|
    #     config.redis = { :namespace => 'myapp', :size => 1, :url => 'redis://myhost:8877/mydb' }
    #   end
    def self.configure
      yield self
    end

    def self.redis(&block)
      fail ArgumentError, 'requires a block' unless block
      @redis ||= Pushr::RedisConnection.create
      @redis.with(&block)
    end

    def self.redis=(hash)
      if hash.is_a?(Hash)
        @redis = RedisConnection.create(hash)
        options[:namespace] ||= hash[:namespace]
      elsif hash.is_a?(ConnectionPool)
        @redis = hash
      else
        fail ArgumentError, 'redis= requires a Hash or ConnectionPool'
      end
    end

    def self.external_id_tag=(value)
      options[:external_id_tag] = value
    end

    def self.external_id_tag
      options[:external_id_tag]
    end

    # instruments with a block
    def self.instrument(name, payload = {}, &block)
      ActiveSupport::Notifications.instrument(name, payload) do
        yield
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10483870967741936, 'fraction_numerical': 0.003360215053763441, 'mean_word_length': 2.698136645962733, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4394080', 'n_tokens_mistral': 977, 'n_tokens_neox': 943, 'n_words': 231}