<commit_before>module.exports = class ABAC {
  constructor (rules) {
    if (!rules['*']) {
      rules['*'] = () => false
    }
    this.rules = rules
  }

  can (user, param, resource) {
    return ['*', param].some((_param, i) => {
      let rules = this.rules[_param]
      if (!rules) return false
      if (typeof rules === 'function') {
        rules = [ rules ]
      } else if (rules.as) {
        rules = this.rules[rules.as]
      }
      return rules.some(rule => {
        return i == 0?
          rule(user, param, resource) : rule(user, resource)
      })
    })
  }

  cant (user, param, resource) {
    return (!this.can(user, param, resource))
  }
}<commit_msg>Added 'with' method<commit_after>class ABAC {
  constructor (rules) {
    if (!rules['*']) {
      rules['*'] = () => false
    }
    this.rules = rules
  }

  can (user, param, resource) {
    return ['*', param].some((_param, i) => {
      let rules = this.rules[_param]
      if (!rules) return false
      if (typeof rules === 'function') {
        rules = [ rules ]
      } else if (rules.as) {
        rules = this.rules[rules.as]
      }
      return rules.some(rule => {
        return i == 0?
          rule(user, param, resource) : rule(user, resource)
      })
    })
  }

  cant (user, param, resource) {
    return (!this.can(user, param, resource))
  }

  with (rules) {
    let newRules = Object.assign({}, this.rules)
    Object.keys(rules).forEach(param => {
      newRules[param] = rules[param]
    })
    return new ABAC(newRules)
  }
}

module.exports = ABAC
{'fraction_non_alphanumeric': 0.1689145793192036, 'fraction_numerical': 0.0012845215157353885, 'mean_word_length': 2.1991786447638604, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '2413721', 'n_tokens_mistral': 517, 'n_tokens_neox': 510, 'n_words': 123}