Skip to content

Commit

Permalink
Use module_function instead of self.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericproulx committed Apr 1, 2024
1 parent 6ebeab6 commit d8389ec
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/grape/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@

module Grape
module Validations
def self.validators
module_function
def validators
@validators ||= {}
end

# Register a new validator, so it can be used to validate parameters.
# @param short_name [String] all lower-case, no spaces
# @param klass [Class] the validator class. Should inherit from
# Grape::Validations::Validators::Base.
def self.register_validator(short_name, klass)
def register_validator(short_name, klass)
validators[short_name] = klass
end

def self.deregister_validator(short_name)
def deregister_validator(short_name)
validators.delete(short_name)
end

def self.require_validator(short_name)
def require_validator(short_name)
str_name = short_name.to_s
validators.fetch(str_name) { Grape::Validations::Validators.const_get(:"#{str_name.camelize}Validator") }
rescue NameError
Expand Down

0 comments on commit d8389ec

Please sign in to comment.