diff --git a/.yardopts b/.yardopts index 4c188ee..c927a86 100644 --- a/.yardopts +++ b/.yardopts @@ -1,6 +1,5 @@ --private --protected -lib/**/*.rb - LICENSE README.md diff --git a/lib/rest_framework.rb b/lib/rest_framework.rb index 8ec6c56..af369db 100644 --- a/lib/rest_framework.rb +++ b/lib/rest_framework.rb @@ -179,11 +179,11 @@ def self.features end end -require_relative "rest_framework/controller_mixins" require_relative "rest_framework/engine" require_relative "rest_framework/errors" require_relative "rest_framework/filters" require_relative "rest_framework/generators" +require_relative "rest_framework/mixins" require_relative "rest_framework/paginators" require_relative "rest_framework/routers" require_relative "rest_framework/serializers" diff --git a/lib/rest_framework/controller_mixins.rb b/lib/rest_framework/controller_mixins.rb deleted file mode 100644 index 2004bd8..0000000 --- a/lib/rest_framework/controller_mixins.rb +++ /dev/null @@ -1,7 +0,0 @@ -module RESTFramework::ControllerMixins -end - -require_relative "controller_mixins/base" - -require_relative "controller_mixins/bulk" -require_relative "controller_mixins/models" diff --git a/lib/rest_framework/mixins.rb b/lib/rest_framework/mixins.rb new file mode 100644 index 0000000..b8663ac --- /dev/null +++ b/lib/rest_framework/mixins.rb @@ -0,0 +1,7 @@ +module RESTFramework::Mixins +end + +require_relative "mixins/base_controller_mixin" + +require_relative "mixins/bulk_model_controller_mixin" +require_relative "mixins/model_controller_mixin" diff --git a/lib/rest_framework/controller_mixins/base.rb b/lib/rest_framework/mixins/base_controller_mixin.rb similarity index 98% rename from lib/rest_framework/controller_mixins/base.rb rename to lib/rest_framework/mixins/base_controller_mixin.rb index 3b3263c..fabc8fa 100644 --- a/lib/rest_framework/controller_mixins/base.rb +++ b/lib/rest_framework/mixins/base_controller_mixin.rb @@ -1,11 +1,7 @@ -require_relative "../errors" -require_relative "../serializers" -require_relative "../utils" - # This module provides the common functionality for any controller mixins, a `root` action, and # the ability to route arbitrary actions with `extra_actions`. This is also where `api_response` # is defined. -module RESTFramework::BaseControllerMixin +module RESTFramework::Mixins::BaseControllerMixin RRF_BASE_CONFIG = { extra_actions: nil, extra_member_actions: nil, @@ -348,3 +344,6 @@ def options return api_response(self.get_options_metadata) end end + +# Alias for convenience. +RESTFramework::BaseControllerMixin = RESTFramework::Mixins::BaseControllerMixin diff --git a/lib/rest_framework/controller_mixins/bulk.rb b/lib/rest_framework/mixins/bulk_model_controller_mixin.rb similarity index 80% rename from lib/rest_framework/controller_mixins/bulk.rb rename to lib/rest_framework/mixins/bulk_model_controller_mixin.rb index 7339c95..1592f5f 100644 --- a/lib/rest_framework/controller_mixins/bulk.rb +++ b/lib/rest_framework/mixins/bulk_model_controller_mixin.rb @@ -1,8 +1,8 @@ -require_relative "models" +require_relative "model_controller_mixin" # Mixin for creating records in bulk. This is unique compared to update/destroy because we overload # the existing `create` action to support bulk creation. -module RESTFramework::BulkCreateModelMixin +module RESTFramework::Mixins::BulkCreateModelMixin # While bulk update/destroy are obvious because they create new router endpoints, bulk create # overloads the existing collection `POST` endpoint, so we add a special key to the options # metadata to indicate bulk create is supported. @@ -31,8 +31,11 @@ def create_all! end end +# Alias for convenience. +RESTFramework::BulkCreateModelMixin = RESTFramework::Mixins::BulkCreateModelMixin + # Mixin for updating records in bulk. -module RESTFramework::BulkUpdateModelMixin +module RESTFramework::Mixins::BulkUpdateModelMixin def update_all records = self.update_all! serialized_records = self.bulk_serialize(records) @@ -56,8 +59,11 @@ def update_all! end end +# Alias for convenience. +RESTFramework::BulkUpdateModelMixin = RESTFramework::Mixins::BulkUpdateModelMixin + # Mixin for destroying records in bulk. -module RESTFramework::BulkDestroyModelMixin +module RESTFramework::Mixins::BulkDestroyModelMixin def destroy_all if params[:_json].is_a?(Array) records = self.destroy_all! @@ -83,8 +89,11 @@ def destroy_all! end end +# Alias for convenience. +RESTFramework::BulkDestroyModelMixin = RESTFramework::Mixins::BulkDestroyModelMixin + # Mixin that includes all the CRUD bulk mixins. -module RESTFramework::BulkModelControllerMixin +module RESTFramework::Mixins::BulkModelControllerMixin include RESTFramework::ModelControllerMixin include RESTFramework::BulkCreateModelMixin @@ -95,3 +104,6 @@ def self.included(base) RESTFramework::ModelControllerMixin.included(base) end end + +# Alias for convenience. +RESTFramework::BulkModelControllerMixin = RESTFramework::Mixins::BulkModelControllerMixin diff --git a/lib/rest_framework/controller_mixins/models.rb b/lib/rest_framework/mixins/model_controller_mixin.rb similarity index 95% rename from lib/rest_framework/controller_mixins/models.rb rename to lib/rest_framework/mixins/model_controller_mixin.rb index 04c4bac..78a698a 100644 --- a/lib/rest_framework/controller_mixins/models.rb +++ b/lib/rest_framework/mixins/model_controller_mixin.rb @@ -1,8 +1,5 @@ -require_relative "base" -require_relative "../filters" - # This module provides the core functionality for controllers based on models. -module RESTFramework::BaseModelControllerMixin +module RESTFramework::Mixins::BaseModelControllerMixin BASE64_REGEX = /data:(.*);base64,(.*)/ BASE64_TRANSLATE = ->(field, value) { _, content_type, payload = value.match(BASE64_REGEX).to_a @@ -634,8 +631,11 @@ def bulk_serialize(records) end end +# Alias for convenience. +RESTFramework::BaseModelControllerMixin = RESTFramework::Mixins::BaseModelControllerMixin + # Mixin for listing records. -module RESTFramework::ListModelMixin +module RESTFramework::Mixins::ListModelMixin def index return api_response(self.get_index_records) end @@ -662,15 +662,21 @@ def get_index_records end end +# Alias for convenience. +RESTFramework::ListModelMixin = RESTFramework::Mixins::ListModelMixin + # Mixin for showing records. -module RESTFramework::ShowModelMixin +module RESTFramework::Mixins::ShowModelMixin def show return api_response(self.get_record) end end +# Alias for convenience. +RESTFramework::ShowModelMixin = RESTFramework::Mixins::ShowModelMixin + # Mixin for creating records. -module RESTFramework::CreateModelMixin +module RESTFramework::Mixins::CreateModelMixin def create return api_response(self.create!, status: :created) end @@ -681,8 +687,11 @@ def create! end end +# Alias for convenience. +RESTFramework::CreateModelMixin = RESTFramework::Mixins::CreateModelMixin + # Mixin for updating records. -module RESTFramework::UpdateModelMixin +module RESTFramework::Mixins::UpdateModelMixin def update return api_response(self.update!) end @@ -695,8 +704,11 @@ def update! end end +# Alias for convenience. +RESTFramework::UpdateModelMixin = RESTFramework::Mixins::UpdateModelMixin + # Mixin for destroying records. -module RESTFramework::DestroyModelMixin +module RESTFramework::Mixins::DestroyModelMixin def destroy self.destroy! return api_response("") @@ -708,8 +720,11 @@ def destroy! end end +# Alias for convenience. +RESTFramework::DestroyModelMixin = RESTFramework::Mixins::DestroyModelMixin + # Mixin that includes show/list mixins. -module RESTFramework::ReadOnlyModelControllerMixin +module RESTFramework::Mixins::ReadOnlyModelControllerMixin include RESTFramework::BaseModelControllerMixin include RESTFramework::ListModelMixin @@ -720,8 +735,11 @@ def self.included(base) end end +# Alias for convenience. +RESTFramework::ReadOnlyModelControllerMixin = RESTFramework::Mixins::ReadOnlyModelControllerMixin + # Mixin that includes all the CRUD mixins. -module RESTFramework::ModelControllerMixin +module RESTFramework::Mixins::ModelControllerMixin include RESTFramework::BaseModelControllerMixin include RESTFramework::ListModelMixin @@ -734,3 +752,6 @@ def self.included(base) RESTFramework::BaseModelControllerMixin.included(base) end end + +# Alias for convenience. +RESTFramework::ModelControllerMixin = RESTFramework::Mixins::ModelControllerMixin diff --git a/lib/rest_framework/routers.rb b/lib/rest_framework/routers.rb index 5f6719f..0592d9f 100644 --- a/lib/rest_framework/routers.rb +++ b/lib/rest_framework/routers.rb @@ -1,5 +1,4 @@ require "action_dispatch/routing/mapper" -require_relative "utils" module ActionDispatch::Routing class Mapper diff --git a/rest_framework.gemspec b/rest_framework.gemspec index 7a97de5..7a91dd5 100644 --- a/rest_framework.gemspec +++ b/rest_framework.gemspec @@ -25,6 +25,7 @@ Gem::Specification.new do |spec| "README.md", "LICENSE", "VERSION", + ".yardopts", *Dir["app/**/*"], *Dir["lib/**/*.rb"], *Dir["vendor/assets/**/*"],