abc_jsonapi 0.3.1 → 0.4.0
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/.gitignore +0 -0
- data/.ruby-version +1 -0
- data/Gemfile +0 -0
- data/Gemfile.lock +10 -10
- data/LICENSE +0 -0
- data/README.md +1 -1
- data/Rakefile +0 -0
- data/abc_jsonapi.gemspec +1 -1
- data/lib/abc_jsonapi.rb +0 -0
- data/lib/abc_jsonapi/collection.rb +0 -0
- data/lib/abc_jsonapi/helpers.rb +0 -0
- data/lib/abc_jsonapi/included_resource.rb +1 -10
- data/lib/abc_jsonapi/model.rb +2 -1
- data/lib/abc_jsonapi/relationship.rb +5 -3
- data/lib/abc_jsonapi/serializer.rb +0 -0
- data/lib/abc_jsonapi/version.rb +1 -1
- data/lib/abc_jsonapi/virtual_attribute.rb +0 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b725447e6db2cf836a64a8ccd803b09c7fdd89a4c64e7fed309e4e0f0ecc0481
|
4
|
+
data.tar.gz: 4fb31c6e2f7f0167412f6a1180633f0b29e3d273f7ab93479d8d565d5f40016d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3a9e47f797ffe9350add1942052ef99f3200c3a9d0c04c87e43c97fbf8187c5ce5103e7cd665ac1351e923b46370b9ce5242fa3edf99a859081ffaa11a172a3
|
7
|
+
data.tar.gz: f7d10191d156c00edaac433ee3bc0b33549dac281bd998a91a3ff4098a0a402aacf253277c8a65200701a98de2eb052b3087052e11b6e9a263a492e101c7ed62
|
data/.gitignore
CHANGED
File without changes
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.5
|
data/Gemfile
CHANGED
File without changes
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
abc_jsonapi (0.
|
4
|
+
abc_jsonapi (0.4.0)
|
5
5
|
activesupport (>= 5.2)
|
6
6
|
i18n
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (6.0.
|
11
|
+
activesupport (6.0.2.2)
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
13
|
i18n (>= 0.7, < 2)
|
14
14
|
minitest (~> 5.1)
|
@@ -16,17 +16,17 @@ GEM
|
|
16
16
|
zeitwerk (~> 2.2)
|
17
17
|
byebug (11.0.1)
|
18
18
|
coderay (1.1.2)
|
19
|
-
concurrent-ruby (1.1.
|
19
|
+
concurrent-ruby (1.1.6)
|
20
20
|
diff-lcs (1.3)
|
21
|
-
i18n (1.
|
21
|
+
i18n (1.8.2)
|
22
22
|
concurrent-ruby (~> 1.0)
|
23
23
|
method_source (0.9.2)
|
24
|
-
minitest (5.
|
24
|
+
minitest (5.14.0)
|
25
25
|
pg (1.1.4)
|
26
26
|
pry (0.12.2)
|
27
27
|
coderay (~> 1.1.0)
|
28
28
|
method_source (~> 0.9.0)
|
29
|
-
rake (
|
29
|
+
rake (13.0.1)
|
30
30
|
rspec (3.8.0)
|
31
31
|
rspec-core (~> 3.8.0)
|
32
32
|
rspec-expectations (~> 3.8.0)
|
@@ -42,9 +42,9 @@ GEM
|
|
42
42
|
rspec-support (3.8.2)
|
43
43
|
sequel (5.21.0)
|
44
44
|
thread_safe (0.3.6)
|
45
|
-
tzinfo (1.2.
|
45
|
+
tzinfo (1.2.6)
|
46
46
|
thread_safe (~> 0.1)
|
47
|
-
zeitwerk (2.
|
47
|
+
zeitwerk (2.3.0)
|
48
48
|
|
49
49
|
PLATFORMS
|
50
50
|
ruby
|
@@ -55,9 +55,9 @@ DEPENDENCIES
|
|
55
55
|
byebug
|
56
56
|
pg
|
57
57
|
pry
|
58
|
-
rake (~>
|
58
|
+
rake (~> 13.0)
|
59
59
|
rspec (~> 3.0)
|
60
60
|
sequel
|
61
61
|
|
62
62
|
BUNDLED WITH
|
63
|
-
2.
|
63
|
+
2.1.2
|
data/LICENSE
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -35,7 +35,7 @@ Or install it yourself as:
|
|
35
35
|
|
36
36
|
Syntax is very similar to Active Model Serializer.
|
37
37
|
|
38
|
-
The serializer is able to work with any ruby objects. Not only ActiveRecord.
|
38
|
+
The serializer is able to work with any ruby objects. Not only ActiveRecord. It calls objects methods to get all the data.
|
39
39
|
|
40
40
|
#### Model Example
|
41
41
|
|
data/Rakefile
CHANGED
File without changes
|
data/abc_jsonapi.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.require_paths = ["lib"]
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 2.0"
|
26
|
-
spec.add_development_dependency "rake", "~>
|
26
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
27
27
|
spec.add_development_dependency "rspec", "~> 3.0"
|
28
28
|
spec.add_development_dependency "pry"
|
29
29
|
spec.add_development_dependency "sequel"
|
data/lib/abc_jsonapi.rb
CHANGED
File without changes
|
File without changes
|
data/lib/abc_jsonapi/helpers.rb
CHANGED
File without changes
|
@@ -30,7 +30,7 @@ module AbcJsonapi
|
|
30
30
|
|
31
31
|
# Get included resource
|
32
32
|
if resource.is_a?(Enumerable)
|
33
|
-
resource =
|
33
|
+
resource = collection.map{ |res| res.public_send(inc_resource_name) }.flatten.reject(&:nil?).uniq{ |item| item.id }
|
34
34
|
else
|
35
35
|
resource = resource.public_send(inc_resource_name)
|
36
36
|
end
|
@@ -48,15 +48,6 @@ module AbcJsonapi
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
def included_items_from_collection(collection, include_name, block = nil)
|
52
|
-
# Run custom include strategy if block given. Otherwise run default method
|
53
|
-
if block.present?
|
54
|
-
block.call(collection)
|
55
|
-
else
|
56
|
-
collection.map{ |res| res.public_send(include_name) }.flatten.reject(&:nil?).uniq{ |item| item.id }
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
51
|
def serializer(included_resource_name)
|
61
52
|
(serializer_namespace + included_resource_name.to_s.classify + 'Serializer').constantize
|
62
53
|
end
|
data/lib/abc_jsonapi/model.rb
CHANGED
@@ -48,7 +48,8 @@ module AbcJsonapi
|
|
48
48
|
rel_model = AbcJsonapi::Relationship.new(
|
49
49
|
model: model,
|
50
50
|
relationship: relationship[:name],
|
51
|
-
type: relationship[:type]
|
51
|
+
type: relationship[:type],
|
52
|
+
block: relationship[:block]
|
52
53
|
)
|
53
54
|
result[relationship[:name].to_sym] = rel_model.serializable_hash
|
54
55
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module AbcJsonapi
|
2
2
|
class Relationship
|
3
|
-
attr_reader :model, :relationship, :type
|
3
|
+
attr_reader :model, :relationship, :type, :block
|
4
4
|
|
5
|
-
def initialize(model:, relationship:, type:)
|
5
|
+
def initialize(model:, relationship:, type:, block:)
|
6
6
|
@model = model
|
7
7
|
@relationship = relationship
|
8
8
|
@type = type
|
9
|
+
@block = block
|
9
10
|
end
|
10
11
|
|
11
12
|
def serializable_hash
|
@@ -31,7 +32,8 @@ module AbcJsonapi
|
|
31
32
|
end
|
32
33
|
|
33
34
|
def serialize_has_many
|
34
|
-
|
35
|
+
rels = block.present? ? block.call(model) : model.public_send(relationship)
|
36
|
+
data = rels.map do |relation|
|
35
37
|
{
|
36
38
|
id: relation.id.to_s,
|
37
39
|
type: Helpers.pluralize_if_necessary(relationship.to_s).to_sym
|
File without changes
|
data/lib/abc_jsonapi/version.rb
CHANGED
File without changes
|
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zhmakin Evgeniy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -144,6 +144,7 @@ extensions: []
|
|
144
144
|
extra_rdoc_files: []
|
145
145
|
files:
|
146
146
|
- ".gitignore"
|
147
|
+
- ".ruby-version"
|
147
148
|
- Gemfile
|
148
149
|
- Gemfile.lock
|
149
150
|
- LICENSE
|
@@ -180,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
181
|
- !ruby/object:Gem::Version
|
181
182
|
version: '0'
|
182
183
|
requirements: []
|
183
|
-
rubygems_version: 3.0.
|
184
|
+
rubygems_version: 3.0.3
|
184
185
|
signing_key:
|
185
186
|
specification_version: 4
|
186
187
|
summary: Json API serializer gem
|