<commit_before>module Af
  class Application
    # Proxy's are used by dependant classes to reach back to the Application frame for
    # some functionality.
    #
    # consider a model that wishes to use the logging functionality of Af:
    #
    #    class Foo < ActiveRecord::Base
    #      include ::Af::Application::SafeProxy
    #
    #      after_create :do_something_after_create
    #
    #      def foo_logger
    #        return af_logger(self.class.name)
    #      end
    #
    #      private
    #      def do_something_after_create
    #        foo_logger.info "created: #{self.inspect}"
    #      end
    #    end
    #
    # The difference between Proxy and SafeProxy is simply that
    # SafeProxy can be used in classes that may not be in an Af::Application
    # run (ie, models that are shared with a Rails web app where Af::Application
    # is never instantiated)
    #
    module Component
      def self.included(base)
        base.extend(ClassMethods)
      end

      module ClassMethods
        def create_proxy_logger(prefix = "", logger_name = self.class.name)
          if !prefix.blank? && prefix[-1..-1] != '_'
            prefix = "#{prefix}_"
          end
          method_name = "#{prefix}logger"
          class_eval "def #{method_name}; return af_logger('#{logger_name}'); end"
        end

        def opt(long_name = nil, *extra_stuff, &b)
          return ::Af::Application.opt(long_name, *extra_stuff, &b)
        end

        def opt_group(group_name, *extra_stuff, &b)
          if extra_stuff[-1].is_a? Hash
            more_extra_stuff = extra_stuff[-1].merge({:target_container => self, :disabled => true})
          else
            more_extra_stuff = extra_stuff + [{:target_container => self, :disabled => true}]
          end
          return ::Af::Application.opt_group(group_name, *more_extra_stuff, &b)
        end
      end

      def af_logger(logger_name = (af_name || "Unknown"))
        return ::Af::Application.singleton.logger(logger_name)
      end

      def af_name
        return ::Af::Application.singleton.af_name
      end

      def af_application
        return ::Af::Application.singleton.af_name
      end
    end
  end
end<commit_msg>support class loggers<commit_after>module Af
  class Application
    # Proxy's are used by dependant classes to reach back to the Application frame for
    # some functionality.
    #
    # consider a model that wishes to use the logging functionality of Af:
    #
    #    class Foo < ActiveRecord::Base
    #      include ::Af::Application::Component
    #
    #      after_create :do_something_after_create
    #
    #      def foo_logger
    #        return af_logger(self.class.name)
    #      end
    #
    #      private
    #      def do_something_after_create
    #        foo_logger.info "created: #{self.inspect}"
    #      end
    #    end
    #
    # The difference between Proxy and SafeProxy is simply that
    # SafeProxy can be used in classes that may not be in an Af::Application
    # run (ie, models that are shared with a Rails web app where Af::Application
    # is never instantiated)
    #
    module Component
      def self.included(base)
        base.extend(ClassMethods)
      end

      module ClassMethods
        def create_proxy_logger(prefix = "", logger_name = self.name, create_class_method = false)
          prefix = prefix.to_s
          if !prefix.blank? && prefix[-1] != '_'
            prefix = "#{prefix}_"
          end
          method_name = "#{prefix}logger"
          class_eval "def #{create_class_method ? 'self.' : ''}#{method_name}; return af_logger('#{logger_name}'); end"
        end

        def create_class_proxy_logger(prefix = "", logger_name = self.name)
          create_proxy_logger(prefix, logger_name, true)
        end

        def opt(long_name, *extra_stuff, &b)
          return ::Af::Application.opt(long_name, *extra_stuff, &b)
        end

        def opt_group(group_name, *extra_stuff, &b)
          extra_hash = {}
          if extra_stuff[-1].is_a? Hash
            extra_hash = extra_stuff.pop
          end
          extra_stuff.push extra_hash.merge({:target_container => self, :disabled => true})

          return ::Af::Application.opt_group(group_name, *extra_stuff, &b)
        end
      end

      def af_logger(logger_name = (af_name || "Unknown"))
        return ::Af::Application.singleton.logger(logger_name)
      end

      def af_name
        return ::Af::Application.singleton.af_name
      end

      def af_application
        return ::Af::Application.singleton
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09508268059181897, 'fraction_numerical': 0.0013054830287206266, 'mean_word_length': 2.2533616418966735, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7636072', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1314, 'n_words': 356}