forked from RestPack/restpack_serializer
-
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.
raise explicit error when unknown serializer
avoid use of runtime error to distinguish this event from other run time error classes.
- Loading branch information
Showing
2 changed files
with
30 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
class RestPack::Serializer::Factory | ||
def self.create(*identifiers) | ||
serializers = identifiers.map { |identifier| self.classify(identifier) } | ||
serializers.count == 1 ? serializers.first : serializers | ||
end | ||
module RestPack::Serializer | ||
|
||
class UnknownSerializer < StandardError; end | ||
|
||
private | ||
class Factory | ||
|
||
def self.classify(identifier) | ||
normalised_identifier = identifier.to_s.underscore | ||
[normalised_identifier, normalised_identifier.singularize].each do |format| | ||
klass = RestPack::Serializer.class_map[format] | ||
return klass.new if klass | ||
def self.create(*identifiers) | ||
serializers = identifiers.map { |identifier| self.classify(identifier) } | ||
serializers.count == 1 ? serializers.first : serializers | ||
end | ||
|
||
raise "Invalid RestPack::Serializer : #{identifier}" | ||
private | ||
|
||
def self.classify(identifier) | ||
normalised_identifier = identifier.to_s.underscore | ||
[normalised_identifier, normalised_identifier.singularize].each do |format| | ||
klass = RestPack::Serializer.class_map[format] | ||
return klass.new if klass | ||
end | ||
|
||
raise UnknownSerializer.new("Unknown serializer class: #{identifier}") | ||
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