-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix autoload types and validators #2222
Merged
dblock
merged 8 commits into
ruby-grape:master
from
ericproulx:fix_autoload_validators_types
Jan 3, 2022
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e5360da
Rebase master
ericproulx 2722aad
Register ArrayCoercer and SetCoercer when needed since its not automa…
ericproulx 432e8ce
Fix eager_load!
ericproulx 97e1321
Add CHANGELOG entry
ericproulx e553a40
Rebase master
ericproulx f6e1fc0
Rename validator files
ericproulx 844600b
Rubocop
ericproulx 7794935
Capitalize Autoload
ericproulx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'dry-types' | ||
|
||
module Grape | ||
module DryTypes | ||
# Call +Dry.Types()+ to add all registered types to +DryTypes+ which is | ||
# a container in this case. Check documentation for more information | ||
# https://dry-rb.org/gems/dry-types/1.2/getting-started/ | ||
include Dry.Types() | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'grape/validations/attributes_iterator' | ||
require 'grape/validations/single_attribute_iterator' | ||
require 'grape/validations/multiple_attributes_iterator' | ||
require 'grape/validations/params_scope' | ||
require 'grape/validations/types' | ||
|
||
module Grape | ||
# Registry to store and locate known Validators. | ||
module Validations | ||
class << self | ||
attr_accessor :validators | ||
end | ||
module_function | ||
|
||
self.validators = {} | ||
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 | ||
# Validations::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 | ||
|
||
# Find a validator and if not found will try to load it | ||
def require_validator(short_name) | ||
str_name = short_name.to_s | ||
validators.fetch(str_name) do | ||
Grape::Validations::Validators.const_get("#{str_name.camelize}Validator") | ||
end | ||
rescue NameError | ||
raise Grape::Exceptions::UnknownValidator.new(short_name) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capitalize Autoload