<commit_before>import Ember from 'ember'
import layout from './template'

const {
  Component,
  computed,
  defineProperty
} = Ember

export default Component.extend({
  classNameBindings: ['isInvalid:has-error', 'isValid:has-success'],
  classNames: ['rui-validatable-input'],
  layout,
  model: null,
  placeholder: '',
  type: 'text',
  valuePath: '',
  async: false,

  init() {
    this._super(...arguments)
    const valuePath = this.get('valuePath')
    defineProperty(this, 'validation', computed.oneWay(`model.validations.attrs.${valuePath}`))
    defineProperty(this, 'value', computed.alias(`model.${valuePath}`))
  },

  // This method ensures that if presence is required
  // But the initial value is undefined or an empty string
  // (the case with new records) we can still validate even though
  // the `didChange` attr would report it had not

  validatePresenceWithEmptyDefault: computed('value', function() {
    const validationOptions = Object.keys(
      this.get(`model.validations.attrs.${this.get('valuePath')}.options`))

    return (validationOptions.indexOf('presence') !== -1) &&
      (this.get('value') === '') ||
      (this.get('value') === undefined)
  }),

  // The attribute has changed UNLESS
  // the validator includes presence and
  // the value is undefined or empty

  didChange: computed('value', 'model.hasDirtyAttributes', 'model.isSaving', function() {
    if (this.get('validatePresenceWithEmptyDefault')) { return true }

    const attrsChanged = this.get('model') ? this.get('model').changedAttributes() : {}
    return this.get('valuePath') in attrsChanged
  }),

  // Checks for in processing statuses
  // Ensures validations don't show when:
  // input is clean, is validating, model is saving

  validatable: computed(
    'didChange',<commit_msg>Clean up longer than 80 lines<commit_after>import Ember from 'ember'
import layout from './template'

const {
  Component,
  computed,
  defineProperty
} = Ember

export default Component.extend({
  classNameBindings: ['isInvalid:has-error', 'isValid:has-success'],
  classNames: ['rui-validatable-input'],
  layout,
  model: null,
  placeholder: '',
  type: 'text',
  valuePath: '',
  async: false,

  init() {
    this._super(...arguments)
    const valuePath = this.get('valuePath')
    defineProperty(this,
      'validation',
      computed.oneWay(`model.validations.attrs.${valuePath}`))
    defineProperty(this, 'value', computed.alias(`model.${valuePath}`))
  },

  // This method ensures that if presence is required
  // But the initial value is undefined or an empty string
  // (the case with new records) we can still validate even though
  // the `didChange` attr would report it had not

  validatePresenceWithEmptyDefault: computed('value', function() {
    const validationOptions = Object.keys(
      this.get(`model.validations.attrs.${this.get('valuePath')}.options`))

    return (validationOptions.indexOf('presence') !== -1) &&
      (this.get('value') === '') ||
      (this.get('value') === undefined)
  }),

  // The attribute has changed UNLESS
  // the validator includes presence and
  // the value is undefined or empty

  didChange: computed(
    'value',
    'model.hasDirtyAttributes',
    'model.isSaving',
    function() {
      if (this.get('validatePresenceWithEmptyDefault')) { return true }

      const attrsChanged = this.get('model') ?
        this.get('model').changedAttributes() : {}
      return this.get('valuePath') in attrsChanged
    }
  ),

  // Checks for in processing statuses
  // Ensures validations don't show when:
  // input is clean, is validating, model is saving

  validatable: computed(
    'didChange',
{'fraction_non_alphanumeric': 0.14005449591280653, 'fraction_numerical': 0.0010899182561307902, 'mean_word_length': 3.742894056847545, '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': '10875', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1058, 'n_words': 295}