forked from ruby-grape/grape
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clean error_formatter & formatter & parser
- Loading branch information
1 parent
df3e4ae
commit 93e6998
Showing
15 changed files
with
110 additions
and
100 deletions.
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,31 @@ | ||
module Grape | ||
module ErrorFormatter | ||
class << self | ||
def builtin_formatters | ||
{ | ||
serializable_hash: Grape::ErrorFormatter::Json, | ||
json: Grape::ErrorFormatter::Json, | ||
jsonapi: Grape::ErrorFormatter::Json, | ||
txt: Grape::ErrorFormatter::Txt, | ||
xml: Grape::ErrorFormatter::Xml | ||
} | ||
end | ||
|
||
def formatters(options) | ||
builtin_formatters.merge(options[:error_formatters] || {}) | ||
end | ||
|
||
def formatter_for(api_format, options = {}) | ||
spec = formatters(options)[api_format] | ||
case spec | ||
when nil | ||
options[:default_error_formatter] || Grape::ErrorFormatter::Txt | ||
when Symbol | ||
method(spec) | ||
else | ||
spec | ||
end | ||
end | ||
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
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
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,31 @@ | ||
module Grape | ||
module Formatter | ||
class << self | ||
def builtin_formmaters | ||
{ | ||
json: Grape::Formatter::Json, | ||
jsonapi: Grape::Formatter::Json, | ||
serializable_hash: Grape::Formatter::SerializableHash, | ||
txt: Grape::Formatter::Txt, | ||
xml: Grape::Formatter::Xml | ||
} | ||
end | ||
|
||
def formatters(options) | ||
builtin_formmaters.merge(options[:formatters] || {}) | ||
end | ||
|
||
def formatter_for(api_format, options = {}) | ||
spec = formatters(options)[api_format] | ||
case spec | ||
when nil | ||
->(obj, _env) { obj } | ||
when Symbol | ||
method(spec) | ||
else | ||
spec | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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,29 @@ | ||
module Grape | ||
module Parser | ||
class << self | ||
def builtin_parsers | ||
{ | ||
json: Grape::Parser::Json, | ||
jsonapi: Grape::Parser::Json, | ||
xml: Grape::Parser::Xml | ||
} | ||
end | ||
|
||
def parsers(options) | ||
builtin_parsers.merge(options[:parsers] || {}) | ||
end | ||
|
||
def parser_for(api_format, options = {}) | ||
spec = parsers(options)[api_format] | ||
case spec | ||
when nil | ||
nil | ||
when Symbol | ||
method(spec) | ||
else | ||
spec | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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