<commit_before>require 'mixpannenkoek/class_inheritable_attribute'

module Mixpannenkoek
  class Base
    extend ::Mixpannenkoek::ClassInheritableAttribute
    class_inheritable_attribute :_api_key, :_api_secret, :_endpoint, :_default_scope

    # Public: the mixpanel api key
    def self.set_api_key(api_key = nil, &block)
      raise ArgumentError if !api_key.nil? && !block.nil?
      self._api_key = api_key || block
    end

    def self.api_key
      self._api_key.respond_to?(:call) ? self._api_key.call : self._api_key
    end

    # Public: the mixpanel api secret
    def self.set_api_secret(api_secret = nil, &block)
      raise ArgumentError if !api_secret.nil? && !block.nil?
      self._api_secret = api_secret || block
    end

    def self.api_secret
      self._api_secret.respond_to?(:call) ? self._api_secret.call : self._api_secret
    end

    def self.set_endpoint(endpoint = nil, &block)
      raise ArgumentError if !endpoint.nil? && !block.nil?
      self._endpoint = endpoint || block
    end

    def self.endpoint
      self._endpoint.respond_to?(:call) ? self._endpoint.call : self._endpoint
    end

    ### Class methods (for convenience)
    #
    # these methods enable this type of usage:
    # Mixpanel::Query.where(training_name: 'Training XYZ').group('subject_name').results
    #
    ###
    def self.where(condition)
      Mixpannenkoek::Query.new(self).where(condition)
    end

    def self.set(variable)
      Mixpannenkoek::Query.new(self).set(variable)
    end

    def self.group(field)
      Mixpannenkoek::Query.new(self).group(field)
    end
    ###
    ### End class methods

    def self.default_scope(&proc_or_lambda)
      self._default_scope ||= []
      self._default_scope += [proc_or_lambda]
    end

    def self.default_scopes
      self._default_scope ||= []
      self._default_scope.map{ |p| p.call }
    end
  end
end<commit_msg>Minor refactor of Mixpannenkoek::Base<commit_after>require 'mixpannenkoek/class_inheritable_attribute'

module Mixpannenkoek
  class Base
    extend ::Mixpannenkoek::ClassInheritableAttribute
    class_inheritable_attribute :_api_key, :_api_secret, :_endpoint, :_default_scope

    def self.set_api_key(api_key = nil, &block)
      self._api_key = value_or_block(api_key, &block)
    end

    def self.set_api_secret(api_secret = nil, &block)
      self._api_secret = value_or_block(api_secret, &block)
    end

    def self.set_endpoint(endpoint = nil, &block)
      self._endpoint = value_or_block(endpoint, &block)
    end

    def self.api_key
      value_from_block(self._api_key)
    end

    def self.api_secret
      value_from_block(self._api_secret)
    end

    def self.endpoint
      value_from_block(self._endpoint)
    end

    ### Class methods (for convenience)
    #
    # these methods enable this type of usage:
    # Mixpanel::Query.where(training_name: 'Training XYZ').group('subject_name').results
    #
    ###
    def self.where(condition)
      Mixpannenkoek::Query.new(self).where(condition)
    end

    def self.set(variable)
      Mixpannenkoek::Query.new(self).set(variable)
    end

    def self.group(field)
      Mixpannenkoek::Query.new(self).group(field)
    end
    ###
    ### End class methods

    def self.default_scope(&proc_or_lambda)
      self._default_scope ||= []
      self._default_scope += [proc_or_lambda]
    end

    def self.default_scopes
      self._default_scope ||= []
      self._default_scope.map{ |p| p.call }
    end

    private
    def self.value_or_block(value, &block)
      raise ArgumentError unless !!value ^ !!block
      value || block
    end

    def self.value_from_block(value_or_proc)
      value_or_proc.respond_to?(:call) ? value_or_proc.call : value_or_proc
    end
  end
end
{'fraction_non_alphanumeric': 0.10437800320341697, 'fraction_numerical': 0.0, 'mean_word_length': 3.1959686450167974, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2727870', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1220, 'n_words': 237}