Skip to content

Commit 5d82922

Browse files
committed
Rename "jsonapi_serialize" to "jsonapi_format"
1 parent c178f67 commit 5d82922

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,15 @@ jsonapi_render json: { data: { id: 1, first_name: 'Tiago' } }, options: { model:
6868
jsonapi_render json: { data: [{ id: 1, first_name: 'Tiago' }, { id: 2, first_name: 'Doug' }] }, options: { model: User }
6969
```
7070

71-
### jsonapi_serialize
71+
### jsonapi_format
7272

7373
In the backstage this is the method that actually parses ActiveRecord/Hash objects and builds a new Hash compliant with JSON API. It can be called anywhere in your controllers being very useful whenever you need to work with a JSON API "serialized" version of your object before rendering it.
7474

75+
Note: because of semantic reasons `JSONAPI::Utils#jsonapi_serialize` was renamed being now just an alias to `JSONAPI::Utils#jsonapi_format`.
76+
7577
```ruby
7678
def index
77-
result = do_some_magic(jsonapi_serialize(User.all))
79+
result = do_some_magic(jsonapi_format(User.all))
7880
render json: result
7981
end
8082
```

lib/jsonapi/utils/response/formatters.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module JSONAPI
22
module Utils
33
module Response
44
module Formatters
5-
def jsonapi_serialize(records, options = {})
5+
def jsonapi_format(records, options = {})
66
if records.is_a?(Hash)
77
hash = records.with_indifferent_access
88
records = hash_to_active_record(hash[:data], options[:model])
@@ -11,6 +11,10 @@ def jsonapi_serialize(records, options = {})
1111
build_response_document(records, options).contents
1212
end
1313

14+
alias_method :jsonapi_serialize, :jsonapi_format
15+
16+
module_function
17+
1418
def build_response_document(records, options)
1519
results = JSONAPI::OperationResults.new
1620

lib/jsonapi/utils/response/renders.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Utils
33
module Response
44
module Renders
55
def jsonapi_render(json:, status: nil, options: {})
6-
body = jsonapi_serialize(json, options)
6+
body = jsonapi_format(json, options)
77
render json: body, status: status || @_response_document.status
88
rescue => e
99
handle_exceptions(e)

0 commit comments

Comments
 (0)