dry_serialization 0.4.4.2 → 0.4.4.3
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/README.md +21 -2
- data/lib/dry_serialization.rb +1 -0
- data/lib/dry_serialization/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32515881ad6106083773deb7252ed369d179aa499c8955760459c29e740da85c
|
4
|
+
data.tar.gz: b3bfffa4bed91ee6abc05edc66f45d07cee9a56b0865a143c7e5e24880ae9756
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e23aa1a8f4a0b4d27b4c8d2f664c8e149421afa0e4cc2dacd7198cb38f2c43863affe03bb75fe13dfab715b212920facaa42ae4c8fcfe71ef51dd7f8bc8a6db2
|
7
|
+
data.tar.gz: daa8252dcdd1f0aec8e2acc0e8ed61beed8b4f6999cfe20c5de643c52360111793a0946335359e59411f81fcf667f05086556174c334af3939726c466f072cb7
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# DrySerialization
|
2
2
|
|
3
|
-

|
3
|
+
[](https://badge.fury.io/rb/dry_serialization)
|
5
4
|

|
6
5
|
|
7
6
|
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dry_serialization`. To experiment with that code, run `bin/console` for an interactive prompt.
|
@@ -33,7 +32,27 @@ Or install it yourself as:
|
|
33
32
|
`rails g dry_serialization:<serializer_name>:install`
|
34
33
|
|
35
34
|
|
35
|
+
- This gem will assume you have an api controller, and create one if you do not. This is to further keep the api separate from the web controllers.
|
36
|
+
- The inclusion of the module corresponding to your chosen serializer gem will give you access to `#serialized_resource`.
|
37
|
+
- The `#serialized_resource` method also takes an optional 'options' hash. For `jsonapi-serializer`, that can come in the form of the `include` hash and/or `meta` or any of the other options available through that gem. Please see their documentation for all options.
|
38
|
+
- Similarly for `blueprinter` it will also take an optional options hash. Again, please see the official documentation in their repo.
|
39
|
+
```ruby
|
40
|
+
user = User.find(params[:id])
|
41
|
+
render json: serialized_resource(user, UserSerializer) # UserSerializer can be substituted with UserBlueprint if that is the gem you've chosen.
|
42
|
+
```
|
43
|
+
|
44
|
+
- SerializationHelper
|
45
|
+
- This module provides success and error response helper methods.
|
46
|
+
- In your controller you can use them like so:
|
47
|
+
```ruby
|
48
|
+
def create
|
49
|
+
user = User.create(create_user_params)
|
50
|
+
return error_response(user.errors) unless user.errors.empty?
|
36
51
|
|
52
|
+
success_response(user, UserSerializer, :created)
|
53
|
+
end
|
54
|
+
```
|
55
|
+
- Both methods take an optional argument for the status. You can either use the symbol representation or the number code.
|
37
56
|
|
38
57
|
|
39
58
|
## Development
|
data/lib/dry_serialization.rb
CHANGED
@@ -2,6 +2,7 @@ require "dry_serialization/version"
|
|
2
2
|
require "dry_serialization/blueprinter"
|
3
3
|
require "dry_serialization/jsonapi_serializer"
|
4
4
|
require "dry_serialization/concerns/serialization_helper"
|
5
|
+
require "dry_serialization/concerns/deserializable"
|
5
6
|
|
6
7
|
module DrySerialization
|
7
8
|
|