Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe
If blueprinter is used for different things in a single codebase, the global configuration cannot be used.
For example, one might have two APIs (public and internal), and want to use blueprinter for both, but with different configuration for each.
Describe the feature you'd like to see implemented
Deprecate global configuration and move configuration to the base class.
Make it possible to override in subclasses, thereby relying on the common class inheritance pattern to handle "global configuration".
# One group of blueprinters
class PublicApiBlueprint < Blueprinter::Base
# DSL alt 1
config do
sort_fields_by = :definition
end
# DSL alt 2
config.sort_fields_by = :definition
end
class UserBlueprint < PublicApiBlueprint
identifier :uuid
fields :first_name, :last_name
end
# Another group of blueprinters
class InternalApiBlueprint < Blueprinter::Base
# DSL alt 1
config do
sort_fields_by = :score
end
# DSL alt 2
config.sort_fields_by = :score
end
class GroupBlueprint < InternalApiBlueprint
identifier :id
fields :name, :members_count
end
As for making sure configs are not shared (only copied) down the inheritance hiearchy, I'd probably pull in class_attribute
from ActiveSupport (https://guides.rubyonrails.org/active_support_core_extensions.html#class-attributes).
If you want to add it manually there is some inspiration here:
- https://github.com/aws/aws-sdk-ruby-record/pull/124/files#diff-c472e379a508904c94f0edaf4c5094a32ec30d00014575d8b8fe910a4bce8460
- https://stackoverflow.com/questions/1251352/ruby-inherit-code-that-works-with-class-variables (this one doesn't go the whole way though)
Describe alternatives you've considered
No response
Additional context
No response