rest_framework 0.6.7 → 0.6.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rest_framework/controller_mixins/base.rb +41 -12
- data/lib/rest_framework/controller_mixins/models.rb +6 -6
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: fc722756068a8151e2b84e0305b5484cb831c555ecd9a648af883d70e0196036
         | 
| 4 | 
            +
              data.tar.gz: 4c5681012eb56285f7cce8baf6e8b6afb275857c69eab317c8aedb742aee62a2
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 0cc9f1280add8372ae481168786f1069ab8026d81971a75aab809f5614abcef656a16e0386875402a85bf780d3223e22af81b764bbfd996a8003efdf4fbb63e5
         | 
| 7 | 
            +
              data.tar.gz: f8f2a20341a8a418c7dec9bd4a3fdea907ee4778bf7d6ac1557b9a430fe97dfba2e6b1f7bee94a30ad944e8bc3fb5ff77b4030c6d4a3a955f8e7f7a9ee0bd4b2
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0.6. | 
| 1 | 
            +
            0.6.8
         | 
| @@ -36,23 +36,28 @@ module RESTFramework::BaseControllerMixin | |
| 36 36 | 
             
                  {
         | 
| 37 37 | 
             
                    filter_pk_from_request_body: true,
         | 
| 38 38 | 
             
                    exclude_body_fields: [:created_at, :created_by, :updated_at, :updated_by],
         | 
| 39 | 
            -
                    accept_generic_params_as_body_params:  | 
| 39 | 
            +
                    accept_generic_params_as_body_params: false,
         | 
| 40 | 
            +
                    show_backtrace: false,
         | 
| 40 41 | 
             
                    extra_actions: nil,
         | 
| 41 42 | 
             
                    extra_member_actions: nil,
         | 
| 42 43 | 
             
                    filter_backends: nil,
         | 
| 44 | 
            +
                    singleton_controller: nil,
         | 
| 45 | 
            +
                    skip_actions: nil,
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                    # Options related to serialization.
         | 
| 48 | 
            +
                    rescue_unknown_format_with: :json,
         | 
| 49 | 
            +
                    serializer_class: nil,
         | 
| 50 | 
            +
                    serialize_to_json: true,
         | 
| 51 | 
            +
                    serialize_to_xml: true,
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                    # Options related to pagination.
         | 
| 43 54 | 
             
                    paginator_class: nil,
         | 
| 44 55 | 
             
                    page_size: 20,
         | 
| 45 56 | 
             
                    page_query_param: "page",
         | 
| 46 57 | 
             
                    page_size_query_param: "page_size",
         | 
| 47 58 | 
             
                    max_page_size: nil,
         | 
| 48 | 
            -
                    rescue_unknown_format_with: :json,
         | 
| 49 | 
            -
                    serializer_class: nil,
         | 
| 50 | 
            -
                    serialize_to_json: true,
         | 
| 51 | 
            -
                    serialize_to_xml: true,
         | 
| 52 | 
            -
                    singleton_controller: nil,
         | 
| 53 | 
            -
                    skip_actions: nil,
         | 
| 54 59 |  | 
| 55 | 
            -
                    #  | 
| 60 | 
            +
                    # Option to disable serializer adapters by default, mainly introduced because Active Model
         | 
| 56 61 | 
             
                    # Serializers will do things like serialize `[]` into `{"":[]}`.
         | 
| 57 62 | 
             
                    disable_adapters_by_default: true,
         | 
| 58 63 | 
             
                  }.each do |a, default|
         | 
| @@ -83,6 +88,7 @@ module RESTFramework::BaseControllerMixin | |
| 83 88 | 
             
                  base.rescue_from(ActiveRecord::RecordInvalid, with: :record_invalid)
         | 
| 84 89 | 
             
                  base.rescue_from(ActiveRecord::RecordNotSaved, with: :record_not_saved)
         | 
| 85 90 | 
             
                  base.rescue_from(ActiveRecord::RecordNotDestroyed, with: :record_not_destroyed)
         | 
| 91 | 
            +
                  base.rescue_from(ActiveModel::UnknownAttributeError, with: :unknown_attribute_error)
         | 
| 86 92 | 
             
                end
         | 
| 87 93 | 
             
              end
         | 
| 88 94 |  | 
| @@ -126,23 +132,46 @@ module RESTFramework::BaseControllerMixin | |
| 126 132 |  | 
| 127 133 | 
             
              def record_invalid(e)
         | 
| 128 134 | 
             
                return api_response(
         | 
| 129 | 
            -
                  { | 
| 135 | 
            +
                  {
         | 
| 136 | 
            +
                    message: "Record invalid.", errors: e.record&.errors
         | 
| 137 | 
            +
                  }.merge(self.class.show_backtrace ? {exception: e.full_message} : {}),
         | 
| 138 | 
            +
                  status: 400,
         | 
| 130 139 | 
             
                )
         | 
| 131 140 | 
             
              end
         | 
| 132 141 |  | 
| 133 142 | 
             
              def record_not_found(e)
         | 
| 134 | 
            -
                return api_response( | 
| 143 | 
            +
                return api_response(
         | 
| 144 | 
            +
                  {
         | 
| 145 | 
            +
                    message: "Record not found.",
         | 
| 146 | 
            +
                  }.merge(self.class.show_backtrace ? {exception: e.full_message} : {}),
         | 
| 147 | 
            +
                  status: 404,
         | 
| 148 | 
            +
                )
         | 
| 135 149 | 
             
              end
         | 
| 136 150 |  | 
| 137 151 | 
             
              def record_not_saved(e)
         | 
| 138 152 | 
             
                return api_response(
         | 
| 139 | 
            -
                  { | 
| 153 | 
            +
                  {
         | 
| 154 | 
            +
                    message: "Record not saved.", errors: e.record&.errors
         | 
| 155 | 
            +
                  }.merge(self.class.show_backtrace ? {exception: e.full_message} : {}),
         | 
| 156 | 
            +
                  status: 400,
         | 
| 140 157 | 
             
                )
         | 
| 141 158 | 
             
              end
         | 
| 142 159 |  | 
| 143 160 | 
             
              def record_not_destroyed(e)
         | 
| 144 161 | 
             
                return api_response(
         | 
| 145 | 
            -
                  { | 
| 162 | 
            +
                  {
         | 
| 163 | 
            +
                    message: "Record not destroyed.", errors: e.record&.errors
         | 
| 164 | 
            +
                  }.merge(self.class.show_backtrace ? {exception: e.full_message} : {}),
         | 
| 165 | 
            +
                  status: 400,
         | 
| 166 | 
            +
                )
         | 
| 167 | 
            +
              end
         | 
| 168 | 
            +
             | 
| 169 | 
            +
              def unknown_attribute_error(e)
         | 
| 170 | 
            +
                return api_response(
         | 
| 171 | 
            +
                  {
         | 
| 172 | 
            +
                    message: e.message.capitalize,
         | 
| 173 | 
            +
                  }.merge(self.class.show_backtrace ? {exception: e.full_message} : {}),
         | 
| 174 | 
            +
                  status: 400,
         | 
| 146 175 | 
             
                )
         | 
| 147 176 | 
             
              end
         | 
| 148 177 |  | 
| @@ -125,17 +125,17 @@ module RESTFramework::BaseModelControllerMixin | |
| 125 125 | 
             
              def get_body_params
         | 
| 126 126 | 
             
                # Filter the request body and map to strings. Return all params if we cannot resolve a list of
         | 
| 127 127 | 
             
                # allowed parameters or fields.
         | 
| 128 | 
            -
                 | 
| 128 | 
            +
                allowed_params = self.get_allowed_parameters&.map(&:to_s)
         | 
| 129 | 
            +
                body_params = if allowed_params
         | 
| 129 130 | 
             
                  request.request_parameters.select { |p| allowed_params.include?(p) }
         | 
| 130 131 | 
             
                else
         | 
| 131 132 | 
             
                  request.request_parameters
         | 
| 132 133 | 
             
                end
         | 
| 133 134 |  | 
| 134 | 
            -
                # Add query params in place of missing body params, if configured. | 
| 135 | 
            -
                 | 
| 136 | 
            -
             | 
| 137 | 
            -
             | 
| 138 | 
            -
                    if (value = params[k])
         | 
| 135 | 
            +
                # Add query params in place of missing body params, if configured.
         | 
| 136 | 
            +
                if self.class.accept_generic_params_as_body_params && allowed_params
         | 
| 137 | 
            +
                  (allowed_params - body_params.keys).each do |k|
         | 
| 138 | 
            +
                    if value = params[k].presence
         | 
| 139 139 | 
             
                      body_params[k] = value
         | 
| 140 140 | 
             
                    end
         | 
| 141 141 | 
             
                  end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: rest_framework
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.6. | 
| 4 | 
            +
              version: 0.6.8
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Gregory N. Schmit
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2022- | 
| 11 | 
            +
            date: 2022-12-06 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rails
         |