Skip to content

Commit

Permalink
Add protected_gem_typo_protection to rubygem validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Claudius authored and sonalkr132 committed Jun 13, 2019
1 parent 9563103 commit f667870
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/models/rubygem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Rubygem < ApplicationRecord
uniqueness: { case_sensitive: false },
if: :needs_name_validation?
validate :blacklist_names_exclusion
validate :protected_gem_typo_protection

after_create :update_unresolved
before_destroy :mark_unresolved
Expand Down Expand Up @@ -308,6 +309,12 @@ def blacklist_names_exclusion
errors.add :name, "'#{name}' is a reserved gem name."
end

def protected_gem_typo_protection
gem_typo = GemTypo.new(name)
return unless gem_typo.protected_typo?
errors.add :name, "'#{name}' is too close to a typo-protected gem."
end

def update_unresolved
Dependency.where(unresolved_name: name).find_each do |dependency|
dependency.update_resolved(self)
Expand Down

0 comments on commit f667870

Please sign in to comment.