abc_jsonapi 0.2.1 → 0.2.2
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/Gemfile.lock +1 -1
- data/README.md +14 -12
- data/lib/abc_jsonapi/serializer.rb +2 -2
- data/lib/abc_jsonapi/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: f930de70d9fa7967f92ce01a75603086b7c7452115c00960753c687add337dda
|
4
|
+
data.tar.gz: b807f6ce9a7247d9add59c128054f852c969293638f8e952c961cb57fbd71435
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff3689062fb7f110442e9a94ceeda3dd8755b4ea2f838db155d4e1752d97adb85b2f0cd9791193519642158148ac754b579c736da05cabfb46e9c2d811424ab2
|
7
|
+
data.tar.gz: 1eb4f4ff0c4b47d5c0682df1b5a917d687e0f7e172de4f1e91e40d5a9bc1ea2daef9764d2c1cdfe6e6811986857bb764270305d1fe22b09ea4523cb3fb78c053
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# AbcJsonapi
|
2
2
|
|
3
|
-
Minimalistic gem for JSON Serialization according to https://jsonapi.org spec
|
3
|
+
Minimalistic gem for JSON Serialization according to https://jsonapi.org spec.
|
4
|
+
|
4
5
|
Inspired by [https://github.com/Netflix/fast_jsonapi](https://github.com/Netflix/fast_jsonapi)
|
6
|
+
|
5
7
|
Contributions are welcome.
|
6
8
|
|
7
9
|
## Installation
|
@@ -39,7 +41,7 @@ The serializer is able to work with any ruby objects. Not only ActiveRecor
|
|
39
41
|
|
40
42
|
```ruby
|
41
43
|
class Author
|
42
|
-
|
44
|
+
attr_reader :first_name, :last_name, :public_name, :contact_id
|
43
45
|
end
|
44
46
|
```
|
45
47
|
|
@@ -47,11 +49,11 @@ end
|
|
47
49
|
|
48
50
|
```ruby
|
49
51
|
class AuthorSerializer
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
include AbcJsonapi::Serializer
|
53
|
+
resource_type :people (optional)
|
54
|
+
attributes :first_name, :last_name, :public_name
|
55
|
+
belongs_to :contact
|
56
|
+
has_many :books
|
55
57
|
end
|
56
58
|
```
|
57
59
|
|
@@ -64,7 +66,7 @@ Default resource type of direct serializing model is taken from serializer filen
|
|
64
66
|
Jsonapi attributes may be declared with class method of serializer - `attributes`:
|
65
67
|
|
66
68
|
```ruby
|
67
|
-
attributes :first_attribute, :second, *other
|
69
|
+
attributes :first_attribute, :second, *other attributes*
|
68
70
|
```
|
69
71
|
|
70
72
|
`attributes` arguments will be called on serializing model as methods.
|
@@ -73,7 +75,7 @@ Also there is `attribute` method to declare single property. You can pass a bloc
|
|
73
75
|
|
74
76
|
```ruby
|
75
77
|
attribute :date_of_birth do |object|
|
76
|
-
|
78
|
+
object.date_of_birth.strftime("%FT%T.%3N%:z") if object.date_of_birth.present?
|
77
79
|
end
|
78
80
|
```
|
79
81
|
|
@@ -113,9 +115,9 @@ AuthorSerializer.new(resource, options).serialized_json
|
|
113
115
|
|
114
116
|
```ruby
|
115
117
|
AbcJsonapi.configure do |config|
|
116
|
-
|
117
|
-
|
118
|
-
|
118
|
+
config.transform_keys = true
|
119
|
+
config.key_transform_method = "camel"
|
120
|
+
config.pluralize_resources = true
|
119
121
|
end
|
120
122
|
```
|
121
123
|
|
@@ -27,8 +27,8 @@ module AbcJsonapi
|
|
27
27
|
@resource_attributes = self.class.resource_attributes
|
28
28
|
@relationships = self.class.relationships
|
29
29
|
@virtual_attributes = self.class.virtual_attributes
|
30
|
-
@includes = options[:include]
|
31
|
-
@meta = options[:meta]
|
30
|
+
@includes = options[:include] if options[:include].present?
|
31
|
+
@meta = options[:meta] if options[:meta].present?
|
32
32
|
end
|
33
33
|
|
34
34
|
def serializable_hash
|
data/lib/abc_jsonapi/version.rb
CHANGED