<commit_before>## Validations

```ruby
class ReportLikeValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    unless value["Report"]
      record.errors.add(attribute, 'does not appear to be a Report')
    end
  end
end

class Report < ActiveRecord::Base
  validates :name, report_like: true
end
```

```ruby
class LikeValidator < ActiveModel::EachValidator
def initialize(options)
@with = options[:with]
super
end
def validate_each(record, attribute, value)
unless value[@with]
record.errors.add(attribute, "does not appear to be like #{@with}")
end
end
end
```

#### Short-form Validation

```ruby
validates:username,
presence:true, 
format: { with: /[A-Za-z0-9]+/ }, 
length: { minimum: 3 }, <commit_msg>customize error validation<commit_after>## Validations

```ruby
class ReportLikeValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    unless value["Report"]
      record.errors.add(attribute, 'does not appear to be a Report')
    end
  end
end

class Report < ActiveRecord::Base
  validates :name, report_like: true
end
```

```ruby
class LikeValidator < ActiveModel::EachValidator
  def initialize(options)
    @with = options[:with]
super
end
def validate_each(record, attribute, value)
unless value[@with]
record.errors.add(attribute, "does not appear to be like #{@with}")
end
end
end
```

#### Short-form Validation

```ruby
validates:username,
presence:true, 
format: { with: /[A-Za-z0-9]+/ }, 
length: { minimum: 3 }, 
{'fraction_non_alphanumeric': 0.13191205862758162, 'fraction_numerical': 0.003997335109926716, 'mean_word_length': 5.181069958847736, 'pattern_counts': {'":': 0, '<': 9, '<?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': '1524782', 'n_tokens_mistral': 487, 'n_tokens_neox': 464, 'n_words': 140}