Module: RESTFramework::BaseModelControllerMixin

Includes:
BaseControllerMixin
Included in:
ModelControllerMixin, ReadOnlyModelControllerMixin
Defined in:
lib/rest_framework/controller_mixins/models.rb

Overview

This module provides the core functionality for controllers based on models.

Class Method Summary collapse

Methods included from BaseControllerMixin

#root

Class Method Details

.included(base) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rest_framework/controller_mixins/models.rb', line 8

def self.included(base)
  if base.is_a?(Class)
    RESTFramework::BaseControllerMixin.included(base)

    # Add class attributes (with defaults) unless they already exist.
    {
      # Core attributes related to models.
      model: nil,
      recordset: nil,

      # Attributes for configuring record fields.
      fields: nil,
      action_fields: nil,

      # Attributes for finding records.
      find_by_fields: nil,
      find_by_query_param: "find_by",

      # Attributes for create/update parameters.
      allowed_parameters: nil,
      allowed_action_parameters: nil,

      # Attributes for the default native serializer.
      native_serializer_config: nil,
      native_serializer_singular_config: nil,
      native_serializer_plural_config: nil,
      native_serializer_except_query_param: "except",

      # Attributes for default model filtering (and ordering).
      filterset_fields: nil,
      ordering_fields: nil,
      ordering_query_param: "ordering",
      ordering_no_reorder: false,
      search_fields: nil,
      search_query_param: "search",
      search_ilike: false,

      # Other misc attributes.
      create_from_recordset: true,  # Option for `recordset.create` vs `Model.create` behavior.
      filter_recordset_before_find: true,  # Option to control if filtering is done before find.
    }.each do |a, default|
      next if base.respond_to?(a)

      base.class_attribute(a)

      # Set default manually so we can still support Rails 4. Maybe later we can use the default
      # parameter on `class_attribute`.
      base.send(:"#{a}=", default)
    end
  end
end