Module: RESTFramework::BaseModelControllerMixin

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

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
# File 'lib/rest_framework/controller_mixins/models.rb', line 8

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

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

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

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

      # Attributes for the default native serializer.
      native_serializer_config: nil,
      native_serializer_action_config: nil,

      # Attributes for default model filtering (and ordering).
      filterset_fields: nil,
      ordering_fields: nil,
      ordering_query_param: 'ordering',

      # Other misc attributes.
      disable_creation_from_recordset: nil,  # Option to disable `recordset.create` behavior.
    }.each do |a, default|
      unless 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
end