abc_jsonapi 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a96cedf5858ef1a23cdf9a35898055f3fdc755a24e6ca0964de971007cb94a14
4
- data.tar.gz: 9d2e596d5b7fd8d01f8bc5dd156b6336d62acc182b605ef64c45dfd47e8caa50
3
+ metadata.gz: a32de4446187395c51ca0c74337fce16277306c3720a1a3a1343cc7a931ea2eb
4
+ data.tar.gz: d04e65627b5ebfbf07a179256e42468c159adc51a5956638b31a404274d5a745
5
5
  SHA512:
6
- metadata.gz: ef73201e7743a4fd4354c413e11c6fa1267f494428318944438f5311181790d0dc2ea5ab9f38cabc110771cd4adbd227afc0f4d8d66eb62239eefc24fc65b2b9
7
- data.tar.gz: c285d419c355103b866b27e9026d4c59f276d9b1539ff9d16057d0141f14361158498e45489a9dc29987e22544d6ca18cbb6205cbd3972130e1829402adcead8
6
+ metadata.gz: 7d98ad8a97ee7dc9b5ec4cfae77b55be6cbafe06fe64e1cf69c39f0b46f2392c15e1683a412bd82594e9cd07019fddb700831c530c118a12b795ce3344a60adb
7
+ data.tar.gz: cf1b1de98a118746bae5d939a83d524ac60cfd04b1a99423c8f84c6e5bb92ecd31f6339151d0fa4e0268c55e87c9b2a83e7e83b639138775a9bc3f29ec4141f2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- abc_jsonapi (0.1.1)
4
+ abc_jsonapi (0.2.1)
5
5
  activesupport (>= 5.2)
6
6
  i18n
7
7
 
data/README.md CHANGED
@@ -1,36 +1,140 @@
1
1
  # AbcJsonapi
2
2
 
3
3
  Minimalistic gem for JSON Serialization according to https://jsonapi.org spec
4
+ Inspired by [https://github.com/Netflix/fast_jsonapi](https://github.com/Netflix/fast_jsonapi)
5
+ Contributions are welcome.
4
6
 
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
8
10
 
9
11
  ```ruby
12
+
10
13
  gem 'abc_jsonapi'
14
+
11
15
  ```
12
16
 
13
17
  And then execute:
14
18
 
15
- $ bundle
19
+ \$ bundle
16
20
 
17
21
  Or install it yourself as:
18
22
 
19
- $ gem install abc_jsonapi
23
+ \$ gem install abc_jsonapi
24
+
25
+ ## Features
26
+
27
+ - Relationships (belongs_to, has_many, has_one)
28
+ - Compound documents ("include" option)
29
+ - Custom include strategies. It is useful when serializing a collection of records to avoid N+1 problem.
30
+ - _"Virtual"_ attributes or overriding default attribute serializing behavior
20
31
 
21
32
  ## Usage
22
33
 
23
- TODO: Write usage instructions here
34
+ Syntax is very similar to Active Model Serializer.
35
+
36
+ The serializer is able to work with any ruby ​​objects. Not only ActiveRecord. The idea is to use duck typing for getting object attributes, relationships and all other data.
37
+
38
+ #### Model Example
39
+
40
+ ```ruby
41
+ class Author
42
+ attr_reader :first_name, :last_name, :public_name, :contact_id
43
+ end
44
+ ```
45
+
46
+ #### Serializer Definition
47
+
48
+ ```ruby
49
+ class AuthorSerializer
50
+ include AbcJsonapi::Serializer
51
+ resource_type :people (optional)
52
+ attributes :first_name, :last_name, :public_name
53
+ belongs_to :contact
54
+ has_many :books
55
+ end
56
+ ```
57
+
58
+ #### Custom resource type
59
+
60
+ Default resource type of direct serializing model is taken from serializer filename. In case of `AuthorSerializer` with disabled pluralize_resources it will be `"author"`. Resource type of compound documents is downcased class of related object.
61
+
62
+ #### Attributes
63
+
64
+ Jsonapi attributes may be declared with class method of serializer - `attributes`:
65
+
66
+ ```ruby
67
+ attributes :first_attribute, :second, *other
68
+ ```
69
+
70
+ `attributes` arguments will be called on serializing model as methods.
71
+
72
+ Also there is `attribute` method to declare single property. You can pass a block to define the way it should be returned.
73
+
74
+ ```ruby
75
+ attribute :date_of_birth do |object|
76
+ object.date_of_birth.strftime("%FT%T.%3N%:z") if object.stop.present?
77
+ end
78
+ ```
79
+
80
+ #### Serializer usage
81
+
82
+ Return ruby hash:
83
+
84
+ ```ruby
85
+ AuthorSerializer.new(resource).serializable_hash
86
+ ```
87
+
88
+ Return json:
89
+
90
+ ```ruby
91
+ AuthorSerializer.new(resource).serialized_json
92
+ ```
93
+
94
+ ## Compound Documents
95
+
96
+ To include relationships you can pass `include` option at the serializer initialization stage.
97
+
98
+ ```ruby
99
+ options = {}
100
+ options[:include] = :books # or "books"
101
+ AuthorSerializer.new(resource, options).serialized_json
102
+ ```
103
+
104
+ ## Configuration
105
+
106
+ #### Global config options
107
+
108
+ - **transform_keys** (_true/false_) - convert keys to any case or not. Default value: _true_
109
+ - **key_transform_method** (_"camel"_ or _"snake"_) - certain key transform method to use with **transform_keys** option enabled. Default value: _"camel"_
110
+ - **pluralize_resources** (_true/false_) - pluralize all resources types in response by default or not. Default value: _false_
111
+
112
+ #### Usage
113
+
114
+ ```ruby
115
+ AbcJsonapi.configure do |config|
116
+ config.transform_keys = true
117
+ config.key_transform_method = "camel"
118
+ config.pluralize_resources = true
119
+ end
120
+ ```
24
121
 
25
122
  ## Development
26
123
 
27
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
124
+ **TODO**:
125
+
126
+ - Write specs
127
+ - Use custom include relationship strategies for downloading relationships json block (solve N+1 problem when serializing collection).
128
+ - Meta per resource
129
+ - Add other jsonapi features
130
+
131
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
132
 
29
133
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
134
 
31
135
  ## Contributing
32
136
 
33
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/abc_jsonapi.
137
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ezname/abc_jsonapi.
34
138
 
35
139
  ## License
36
140
 
@@ -1,3 +1,3 @@
1
1
  module AbcJsonapi
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abc_jsonapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zhmakin Evgeniy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-17 00:00:00.000000000 Z
11
+ date: 2019-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
180
  - !ruby/object:Gem::Version
181
181
  version: '0'
182
182
  requirements: []
183
- rubygems_version: 3.0.3
183
+ rubygems_version: 3.0.6
184
184
  signing_key:
185
185
  specification_version: 4
186
186
  summary: Json API serializer gem