Module: RESTFramework

Defined in:
lib/rest_framework/version.rb,
lib/rest_framework.rb

Overview

Do not use Rails-specific helper methods here (e.g., ‘blank?`) so the module can run standalone.

Defined Under Namespace

Modules: Errors, Filters, Generators, Mixins, Paginators, Serializers, Utils, Version Classes: Config, Engine

Constant Summary collapse

BUILTIN_ACTIONS =
{
  index: :get,
  new: :get,
  create: :post,
}.freeze
BUILTIN_MEMBER_ACTIONS =
{
  show: :get,
  edit: :get,
  update: [:put, :patch].freeze,
  destroy: :delete,
}.freeze
RRF_BUILTIN_ACTIONS =
{
  options: :options,
}.freeze
RRF_BUILTIN_BULK_ACTIONS =
{
  update_all: [:put, :patch].freeze,
  destroy_all: :delete,
}.freeze
EXTERNAL_CSS_NAME =

We put most vendored external assets into these files to make precompilation and serving faster.

"rest_framework/external.min.css"
EXTERNAL_JS_NAME =
"rest_framework/external.min.js"
EXTERNAL_ASSETS =

We should always add the ‘.min` extension prefix even if the assets are not minified, to avoid sprockets minifying the assets. We target propshaft, so we want these assets to just be passed through. rubocop:disable Layout/LineLength

{
  # Bootstrap
  "bootstrap.min.css" => {
    url: "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css",
    sri: "sha384-aFq/bzH65dt+w6FI2ooMVUpc+21e0SRygnTpmBvdBgSdnuTN7QbdgL+OapgHtvPp",
  },
  "bootstrap.min.js" => {
    url: "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js",
    sri: "sha384-qKXV1j0HvMUeCBQ+QVp7JcfGl760yU08IQ+GpUo5hlbpg51QRiuqHAJz8+BrxE/N",
  },

  # Bootstrap Icons
  "bootstrap-icons.min.css" => {
    url: "https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css",
    inline_fonts: true,
  },

  # Highlight.js
  "highlight.min.js" => {
    url: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js",
    sri: "sha512-bgHRAiTjGrzHzLyKOnpFvaEpGzJet3z4tZnXGjpsCcqOnAH6VGUx9frc5bcIhKTVLEiCO6vEhNAgx5jtLUYrfA==",
  },
  "highlight-json.min.js" => {
    url: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/languages/json.min.js",
    sri: "sha512-0xYvyncS9OLE7GOpNBZFnwyh9+bq4HVgk4yVVYI678xRvE22ASicF1v6fZ1UiST+M6pn17MzFZdvVCI3jTHSyw==",
  },
  "highlight-xml.min.js" => {
    url: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/languages/xml.min.js",
    sri: "sha512-5zBcw+OKRkaNyvUEPlTSfYylVzgpi7KpncY36b0gRudfxIYIH0q0kl2j26uCUB3YBRM6ytQQEZSgRg+ZlBTmdA==",
  },
  "highlight-a11y-dark.min.css" => {
    url: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/a11y-dark.min.css",
    sri: "sha512-Vj6gPCk8EZlqnoveEyuGyYaWZ1+jyjMPg8g4shwyyNlRQl6d3L9At02ZHQr5K6s5duZl/+YKMnM3/8pDhoUphg==",
    extra_tag_attrs: {class: "rrf-dark-mode"},
  },
  "highlight-a11y-light.min.css" => {
    url: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/a11y-light.min.css",
    sri: "sha512-WDk6RzwygsN9KecRHAfm9HTN87LQjqdygDmkHSJxVkVI7ErCZ8ZWxP6T8RvBujY1n2/E4Ac+bn2ChXnp5rnnHA==",
    extra_tag_attrs: {class: "rrf-light-mode"},
  },

  # NeatJSON
  "neatjson.min.js" => {
    url: "https://cdn.jsdelivr.net/npm/[email protected]/javascript/neatjson.min.js",
    exclude_from_docs: true,
  },

  # Trix
  "trix.min.css" => {
    url: "https://unpkg.com/[email protected]/dist/trix.css",
    exclude_from_docs: true,
  },
  "trix.min.js" => {
    url: "https://unpkg.com/[email protected]/dist/trix.umd.min.js",
    exclude_from_docs: true,
  },
}.map { |name, cfg|
  ext = File.extname(name)
  if ext == ".js"
    cfg[:place] = "javascripts"
    cfg[:extra_tag_attrs] ||= {}
    cfg[:tag_attrs] = {
      src: cfg[:url],
      integrity: cfg[:sri],
      crossorigin: "anonymous",
      referrerpolicy: "no-referrer",
      defer: true,
      **cfg[:extra_tag_attrs],
    }
    cfg[:tag] = ActionController::Base.helpers.tag.script(**cfg[:tag_attrs])
  elsif ext == ".css"
    cfg[:place] = "stylesheets"
    cfg[:extra_tag_attrs] ||= {}
    cfg[:tag_attrs] = {
      rel: "stylesheet",
      href: cfg[:url],
      integrity: cfg[:sri],
      crossorigin: "anonymous",
      **cfg[:extra_tag_attrs],
    }
    cfg[:tag] = ActionController::Base.helpers.tag.link(**cfg[:tag_attrs])
  else
    raise "Unknown asset extension: #{ext}."
  end

  [name, cfg]
}.to_h.freeze
EXTERNAL_UNSUMMARIZED_ASSETS =

rubocop:enable Layout/LineLength

EXTERNAL_ASSETS.select { |_, cfg| cfg[:extra_tag_attrs].present? }
VERSION =
Version.get_version
BaseError =

Alias for convenience.

RESTFramework::Errors::BaseError
BaseFilter =

Alias for convenience.

RESTFramework::Filters::BaseFilter
RansackFilter =

Alias for convenience.

RESTFramework::Filters::RansackFilter
BasePaginator =

Alias for convenience.

RESTFramework::Paginators::BasePaginator
UnknownModelError =

Alias for convenience.

RESTFramework::Errors::UnknownModelError
ModelQueryFilter =

Alias for convenience.

RESTFramework::Filters::ModelQueryFilter
ModelSearchFilter =

Alias for convenience.

RESTFramework::Filters::ModelSearchFilter
BaseSerializer =

Alias for convenience.

RESTFramework::Serializers::BaseSerializer
BaseControllerMixin =

Alias for convenience.

RESTFramework::Mixins::BaseControllerMixin
ModelOrderingFilter =

Alias for convenience.

RESTFramework::Filters::ModelOrderingFilter
BaseModelControllerMixin =

Aliases for convenience.

RESTFramework::Mixins::BaseModelControllerMixin
ListModelMixin =
RESTFramework::Mixins::ListModelMixin
ShowModelMixin =
RESTFramework::Mixins::ShowModelMixin
CreateModelMixin =
RESTFramework::Mixins::CreateModelMixin
UpdateModelMixin =
RESTFramework::Mixins::UpdateModelMixin
DestroyModelMixin =
RESTFramework::Mixins::DestroyModelMixin
ReadOnlyModelControllerMixin =
RESTFramework::Mixins::ReadOnlyModelControllerMixin
ModelControllerMixin =
RESTFramework::Mixins::ModelControllerMixin
NativeSerializer =

Alias for convenience.

RESTFramework::Serializers::NativeSerializer
PageNumberPaginator =

Alias for convenience.

RESTFramework::Paginators::PageNumberPaginator
BulkCreateModelMixin =

Aliases for convenience.

RESTFramework::Mixins::BulkCreateModelMixin
BulkUpdateModelMixin =
RESTFramework::Mixins::BulkUpdateModelMixin
BulkDestroyModelMixin =
RESTFramework::Mixins::BulkDestroyModelMixin
BulkModelControllerMixin =
RESTFramework::Mixins::BulkModelControllerMixin
NilPassedToAPIResponseError =

Alias for convenience.

RESTFramework::Errors::NilPassedToAPIResponseError
ActiveModelSerializerAdapterFactory =

Alias for convenience. rubocop:disable Layout/LineLength

RESTFramework::Serializers::ActiveModelSerializerAdapterFactory

Class Method Summary collapse

Class Method Details

.configObject



169
170
171
# File 'lib/rest_framework.rb', line 169

def self.config
  return @config ||= Config.new
end

.configure {|self.config| ... } ⇒ Object

Yields:



173
174
175
# File 'lib/rest_framework.rb', line 173

def self.configure
  yield(self.config)
end

.featuresObject



177
178
179
# File 'lib/rest_framework.rb', line 177

def self.features
  return @features ||= {}
end