-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify jsonapi_class configuration
Adds • JSONAPI::Rails::SerializableClassMapping class Overriding Hash’s lookup can be confusing without creating an descendent class. - Old behavior inferrer.class == Hash Doesn’t make it obvious that there’s custom behavior - New behavior inferrer.class == JSONAPI::Rails::SerializableClassMapping Now it’s obvious where to look for the unusual behavior This setup also allows us to define the default mappings and the lookup behavior in separate configuration options • configuration options for 1. jsonapi_class_mapper 2. jsonapi_class_mappings 3. jsonapi_errors_class_mapper (fallback to jsonapi_class_mapper if nil) 4. jsonapi_errors_class_mappings Removes • configration options for 1. jsonapi_class 2. jsonapi_errors_class
- Loading branch information
1 parent
14a9421
commit 975793f
Showing
4 changed files
with
61 additions
and
27 deletions.
There are no files selected for viewing
36 changes: 24 additions & 12 deletions
36
lib/generators/jsonapi/initializer/templates/initializer.rb
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,13 @@ | ||
module JSONAPI | ||
module Rails | ||
# @private | ||
class SerializableClassMapping < Hash | ||
def initialize(mapper, default_mappings = {}) | ||
super() do |hash, class_name_sym| | ||
hash[class_name_sym] = | ||
mapper.call(class_name_sym.to_s) | ||
end.merge!(default_mappings) | ||
end | ||
end | ||
end | ||
end |