<commit_before>'use strict'
pi = require './pi'
require './utils'
utils = pi.utils

class pi.Core
  # extend class prototype with mixin methods
  @include: (mixins...) ->
    for mixin in mixins
      utils.extend @::, mixin::, true, ['constructor']
      mixin.included @

  # extend class with mixin class methods
  @extend: (mixins...) ->
    for mixin in mixins
      utils.extend @, mixin, true
      mixin.extended @

  @alias: (from, to) ->
    @::[from] = (args...) ->
      @[to].apply(@,args)
    return

  @class_alias: (from, to) ->
    @[from] = @[to]
    return

  # register before and after callbacks for method
  @register_callback: (method, options={}) ->
    callback_name = options.as || method
    for _when in ["before","after"]
      do(_when) =>
        @["#{_when}_#{callback_name}"] = (callback) ->
          (@["_#{_when}_#{callback_name}"]||=[]).push callback
    
    # create callbacked version of a function  
    @::["__#{method}"] = (args...) ->
      @run_callbacks "before_#{callback_name}", args
      res = @constructor::[method].apply(@,args)
      @run_callbacks "after_#{callback_name}", args
      res 

    (@callbacked||=[]).push method

  constructor: ->
    # apply callbacks to methods
    for method in (@constructor.callbacked||[])
      do(method) =>
        @[method] = @["__#{method}"]

  run_callbacks: (type,args) ->
    for callback in (@constructor["_#{type}"]||[])
      callback.call(@,args)

  # delegate methods to another object or nested object/method (then to is string key)
  delegate_to: (to, methods...) ->
    to = if typeof to is 'string' then @[to] else to
    
    for method in methods
      do (method) => 
        @[method] = (args...) ->
          to[method].apply(to, args)
    return<commit_msg>fix callbacks<commit_after>'use strict'
pi = require './pi'
require './utils'
utils = pi.utils

class pi.Core
  # extend class prototype with mixin methods
  @include: (mixins...) ->
    for mixin in mixins
      utils.extend @::, mixin::, true, ['constructor']
      mixin.included @

  # extend class with mixin class methods
  @extend: (mixins...) ->
    for mixin in mixins
      utils.extend @, mixin, true
      mixin.extended @

  @alias: (from, to) ->
    @::[from] = (args...) ->
      @[to].apply(@,args)
    return

  @class_alias: (from, to) ->
    @[from] = @[to]
    return

  # register before and after callbacks for method
  @register_callback: (method, options={}) ->
    callback_name = options.as || method
    for _when in ["before","after"]
      do(_when) =>
        @["#{_when}_#{callback_name}"] = (callback) ->
          if @::["_#{_when}_#{callback_name}"] and not @::hasOwnProperty("_#{_when}_#{callback_name}")
            @::["_#{_when}_#{callback_name}"] = @::["_#{_when}_#{callback_name}"].slice()
          (@::["_#{_when}_#{callback_name}"]||=[]).push callback
    
    # create callbacked version of a function  
    @::["__#{method}"] = (args...) ->
      @run_callbacks "before_#{callback_name}", args
      res = @constructor::[method].apply(@,args)
      @run_callbacks "after_#{callback_name}", args
      res 

    (@callbacked||=[]).push method

  constructor: ->
    # apply callbacks to methods
    for method in (@constructor.callbacked||[])
      do(method) =>
        @[method] = @["__#{method}"]

  run_callbacks: (type,args) ->
    for callback in (@["_#{type}"]||[])
      callback.call(@,args)

  # delegate methods to another object or nested object/method (then to is string key)
  delegate_to: (to, methods...) ->
    to = if typeof to is 'string' then @[to] else to
    
    for method in methods
      do (method) => 
        @[method] = (args...) ->
          to[method].apply(to, args)
    return
{'fraction_non_alphanumeric': 0.18045112781954886, 'fraction_numerical': 0.0, 'mean_word_length': 2.781725888324873, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '5354309', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1201, 'n_words': 315}