<commit_before>require 'reform/rails'

class ExistsInRubygemsDotOrgValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    record.errors[attribute] << "is not the name of a gem registered in http://rubygems.org" if Net::HTTP.get("rubygems.org", "/api/v1/gems/#{value}.json") == "This rubygem could not be found."
  end
end

class RubygemForm < Reform::Form
  include DSL
  include Reform::Form::ActiveRecord

  properties [:name, :status, :notes], on: :rubygem

  attr_accessor :miel # honeypot field for spammers

  model :rubygem

  validates :name,   presence: true, uniqueness: { case_sensitive: false }, exists_in_rubygems_dot_org: true
  validates :status, presence: true, inclusion: Rubygem::STATUSES
  validates :notes,  presence: true
  validates :miel,   format: { without: /.+/ }

  def save params
    rubygem.update(to_h) if validate(params)
  end

end
<commit_msg>Check if gem name has valid format<commit_after>require 'reform/rails'

class ExistsInRubygemsDotOrgValidator < ActiveModel::EachValidator
  def validate_each record, attribute, value
    record.errors[attribute] << "is not the name of a gem registered in http://rubygems.org" if Net::HTTP.get("rubygems.org", "/api/v1/gems/#{value}.json") == "This rubygem could not be found."
  end
end

class HasRubygemNameFormatValidator < ActiveModel::EachValidator
  SPECIAL_CHARACTERS = ".-_"
  ALLOWED_CHARACTERS = "[A-Za-z0-9#{Regexp.escape(SPECIAL_CHARACTERS)}]+"
  NAME_PATTERN       = /\A#{ALLOWED_CHARACTERS}\Z/

  def validate_each record, attribute, value
    record.errors[attribute] << "must include at least one letter" if value !~ /[a-zA-Z]+/
    record.errors[attribute] << "can only include letters, numbers, dashes, and underscores" if value !~ NAME_PATTERN
  end
end

class RubygemForm < Reform::Form
  include DSL
  include Reform::Form::ActiveRecord

  properties [:name, :status, :notes], on: :rubygem

  attr_accessor :miel # honeypot field for spammers

  model :rubygem

  validates :name,   presence: true, uniqueness: { case_sensitive: false }, has_rubygem_name_format: true, exists_in_rubygems_dot_org: true
  validates :status, presence: true, inclusion: Rubygem::STATUSES
  validates :notes,  presence: true
  validates :miel,   format: { without: /.+/ }

  def save params
    rubygem.update(to_h) if validate(params)
  end

end

{'fraction_non_alphanumeric': 0.11323155216284987, 'fraction_numerical': 0.0016963528413910093, 'mean_word_length': 4.725728155339806, 'pattern_counts': {'":': 0, '<': 16, '<?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': '5292055', 'n_tokens_mistral': 811, 'n_tokens_neox': 767, 'n_words': 212}