diff --git a/lib/rest_framework/filters/model_query_filter.rb b/lib/rest_framework/filters/model_query_filter.rb index 50bdca9..6ae6a95 100644 --- a/lib/rest_framework/filters/model_query_filter.rb +++ b/lib/rest_framework/filters/model_query_filter.rb @@ -22,7 +22,7 @@ def _get_filter_params field, sub_field = match[1..2] next false unless field.in?(fields) - sub_fields = @controller.class.get_field_config(field)[:sub_fields] || [] + sub_fields = @controller.class.field_config_for(field)[:sub_fields] || [] if sub_field.in?(sub_fields) includes << field.to_sym next true diff --git a/lib/rest_framework/mixins/base_controller_mixin.rb b/lib/rest_framework/mixins/base_controller_mixin.rb index 4e5877b..85116b4 100644 --- a/lib/rest_framework/mixins/base_controller_mixin.rb +++ b/lib/rest_framework/mixins/base_controller_mixin.rb @@ -341,7 +341,9 @@ def api_response(payload, **kwargs) end end - # Provide a generic `OPTIONS` response with metadata such as available actions. + # TODO: Might make this the default render method in the future. + alias_method :render_api, :api_response + def options return api_response(self.options_metadata) end diff --git a/lib/rest_framework/mixins/model_controller_mixin.rb b/lib/rest_framework/mixins/model_controller_mixin.rb index b1350e0..2fe7f57 100644 --- a/lib/rest_framework/mixins/model_controller_mixin.rb +++ b/lib/rest_framework/mixins/model_controller_mixin.rb @@ -117,10 +117,10 @@ def get_fields(input_fields: nil) end # Get a field's config, including defaults. - def get_field_config(f) + def field_config_for(f) f = f.to_sym - @_get_field_config ||= {} - return @_get_field_config[f] if @_get_field_config[f] + @_field_config_for ||= {} + return @_field_config_for[f] if @_field_config_for[f] config = self.field_config&.dig(f) || {} @@ -147,7 +147,7 @@ def get_field_config(f) }.to_h.compact.presence end - return @_get_field_config[f] = config.compact + return @_field_config_for[f] = config.compact end # Get metadata about the resource's fields. @@ -305,7 +305,7 @@ def fields_metadata end # Serialize any field config. - metadata[:config] = self.get_field_config(f).presence + metadata[:config] = self.field_config_for(f).presence next [f, metadata.compact] }.to_h @@ -450,7 +450,7 @@ def get_allowed_parameters if self.permit_nested_attributes_assignment hash_variations["#{f}_attributes"] = ( - self.class.get_field_config(f)[:sub_fields] + ["_destroy"] + self.class.field_config_for(f)[:sub_fields] + ["_destroy"] ) end diff --git a/lib/rest_framework/serializers/native_serializer.rb b/lib/rest_framework/serializers/native_serializer.rb index d1cf471..d7e1fc1 100644 --- a/lib/rest_framework/serializers/native_serializer.rb +++ b/lib/rest_framework/serializers/native_serializer.rb @@ -195,7 +195,7 @@ def _get_controller_serializer_config(fields) attachment_reflections = @model.attachment_reflections fields.each do |f| - field_config = @controller.class.get_field_config(f) + field_config = @controller.class.field_config_for(f) next if field_config[:write_only] if f.in?(column_names)