<commit_before>$ = require "jquery"
_ = require "underscore"
Backbone = require "backbone"

{logger} = require "./logging"
property_mixins = require "./property_mixins"
refs = require "./util/refs"

class HasProps extends Backbone.Model

  props: {}
  mixins: []

  @define: (name_or_object, type, default_value) ->
    if _.isString(name_or_object)
      name = name_or_object
      prop = if _.isUndefined(default_value) then [type] else [type, default_value]
      object = {}
      object[name] = prop
    else
      object = name_or_object

    for name, prop of object
      if this.prototype.props[name]?
        throw new Error("attempted to redefine property '#{this.name}.#{name}'")

      if this.prototype[name]?
        # XXX: should be an error, but Backbone.Model.url must be removed first
        console.log("attempted to redefine attribute '#{this.name}.#{name}'")

      Object.defineProperty(this.prototype, name, {
        get: ()      -> this.get(name)
        set: (value) -> this.set(name, value)
      }, {
        configurable: false
        enumerable: true
      })

      props = _.clone(this.prototype.props)
      props[name] = prop
      this.prototype.props = props

  @mixin: (names...) ->
    @define(property_mixins.create(names))
    mixins = this.prototype.mixins.concat(names)
    this.prototype.mixins = mixins

  @mixins: (names) -> @mixin(names...)

  @override: (name, default_value) ->
    value = this.prototype.props[name]
    if not value?
      throw new Error("attempted to override property '#{this.name}.#{name}' (which wasn't defined)")
    [type, insignificant_stuff_at_this_point] = value
    props = _.clone(this.prototype.props)<commit_msg>Proper scoping of name and props in HasProps.define()<commit_after>$ = require "jquery"
_ = require "underscore"
Backbone = require "backbone"

{logger} = require "./logging"
property_mixins = require "./property_mixins"
refs = require "./util/refs"

class HasProps extends Backbone.Model

  props: {}
  mixins: []

  @define: (name_or_object, type, default_value) ->
    if _.isString(name_or_object)
      name = name_or_object
      prop = if _.isUndefined(default_value) then [type] else [type, default_value]
      object = {}
      object[name] = prop
    else
      object = name_or_object

    for name, prop of object
      do (name, prop) =>
        if this.prototype.props[name]?
          throw new Error("attempted to redefine property '#{this.name}.#{name}'")

        if this.prototype[name]?
          # XXX: should be an error, but Backbone.Model.url must be removed first
          console.log("attempted to redefine attribute '#{this.name}.#{name}'")

        Object.defineProperty(this.prototype, name, {
          get: ()      -> this.get(name)
          set: (value) -> this.set(name, value)
        }, {
          configurable: false
          enumerable: true
        })

        props = _.clone(this.prototype.props)
        props[name] = prop
        this.prototype.props = props

  @mixin: (names...) ->
    @define(property_mixins.create(names))
    mixins = this.prototype.mixins.concat(names)
    this.prototype.mixins = mixins

  @mixins: (names) -> @mixin(names...)

  @override: (name, default_value) ->
    value = this.prototype.props[name]
    if not value?
      throw new Error("attempted to override property '#{this.name}.#{name}' (which wasn't defined)")
    [type, insignificant_stuff_at_this_point] = value
    props = _.clone(this.prototype.props)
{'fraction_non_alphanumeric': 0.13306567249784915, 'fraction_numerical': 0.0, 'mean_word_length': 2.8885172798216274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '2259111', 'n_tokens_mistral': 1099, 'n_tokens_neox': 1061, 'n_words': 265}