fields-serializer 0.8.5 → 0.9.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/Gemfile +1 -1
- data/fields-serializer.gemspec +8 -8
- data/lib/fields/serializer.rb +3 -4
- data/lib/fields/serializer/action_controller.rb +1 -1
- data/lib/fields/serializer/active_record.rb +3 -3
- data/lib/fields/serializer/fields_tree.rb +11 -11
- data/lib/fields/serializer/version.rb +1 -1
- metadata +5 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 348aaf9bdec62afafbd167fd030af41252db410c
|
4
|
+
data.tar.gz: 6510cbd3b125a24afb71b84692a706dc6829f1b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61990d7a0253325bce54249af00df9fc6d42d2daf84b53c1b9cbde5c5786a254e166fed4088a52f6f3e2b9acf8f183f9bec487bb687847e9eee8a39ae7a7d7ca
|
7
|
+
data.tar.gz: bcfa76eb2cf5791f003764063f0d8a6854392711239c4c3a55092b12a18b88382149fe3ab4138d06485db80a726de7be8852be562fdbc1c7171c522ec6ab1929
|
data/Gemfile
CHANGED
data/fields-serializer.gemspec
CHANGED
@@ -6,8 +6,8 @@ require "fields/serializer/version"
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "fields-serializer"
|
8
8
|
spec.version = Fields::Serializer::VERSION
|
9
|
-
spec.authors = ["
|
10
|
-
spec.email = ["
|
9
|
+
spec.authors = ["Lorenzo Tello"]
|
10
|
+
spec.email = ["ltello8a@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = "Extensions to ActiveRecord and ActionController to serialize a subset of model fields"
|
13
13
|
spec.description = "Extensions to ActiveRecord and ActionController to serialize a subset of model fields"
|
@@ -21,13 +21,13 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.add_development_dependency "bundler",
|
25
|
-
spec.add_development_dependency "rake",
|
26
|
-
spec.add_development_dependency "rspec",
|
27
|
-
spec.add_development_dependency "
|
28
|
-
spec.add_development_dependency "byebug",
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.6"
|
27
|
+
spec.add_development_dependency "factory_bot", "~> 4.8"
|
28
|
+
spec.add_development_dependency "byebug", "~> 5.0"
|
29
29
|
spec.add_development_dependency "simplecov"
|
30
30
|
|
31
|
-
spec.add_runtime_dependency "rails",
|
31
|
+
spec.add_runtime_dependency "rails", "~> 5.0"
|
32
32
|
spec.add_runtime_dependency "active_model_serializers", "~> 0.10"
|
33
33
|
end
|
data/lib/fields/serializer.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "active_support"
|
2
|
+
require "active_support/core_ext"
|
3
|
+
require "active_support/concern"
|
4
4
|
require "fields/serializer/version"
|
5
5
|
require "fields/serializer/active_record"
|
6
6
|
require "fields/serializer/action_controller"
|
@@ -8,7 +8,6 @@ require "fields/serializer/fields_tree"
|
|
8
8
|
|
9
9
|
module Fields
|
10
10
|
module Serializer
|
11
|
-
|
12
11
|
ActiveSupport.on_load(:active_record) do
|
13
12
|
include Fields::Serializer::ActiveRecord
|
14
13
|
end
|
@@ -18,7 +18,7 @@ module Fields
|
|
18
18
|
if fields.present?
|
19
19
|
if optimize_query
|
20
20
|
includes = model_class.fields_to_includes(fields)
|
21
|
-
query = query.includes(*includes)
|
21
|
+
query = query.includes(*Array.wrap(includes)) if includes
|
22
22
|
end
|
23
23
|
options.merge!(each_serializer: model_class.fields_serializer(fields), include: "**")
|
24
24
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require "active_record"
|
2
2
|
require "active_model_serializers"
|
3
|
-
require_relative
|
3
|
+
require_relative "active_record/errors"
|
4
4
|
|
5
5
|
module Fields
|
6
6
|
module Serializer
|
@@ -11,7 +11,7 @@ module Fields
|
|
11
11
|
class_methods do
|
12
12
|
# If key is an association of a given model class
|
13
13
|
def association?(key)
|
14
|
-
reflections.
|
14
|
+
reflections.key?(key.to_s)
|
15
15
|
end
|
16
16
|
|
17
17
|
# Convert a list of fields (json_api notation) in a list of associations to be
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "active_record"
|
2
2
|
require "active_model_serializers"
|
3
3
|
|
4
4
|
module Fields
|
@@ -13,12 +13,12 @@ module Fields
|
|
13
13
|
@fields = []
|
14
14
|
@associations = {}
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
# Self if any fields or associations. Nil otherwise
|
18
18
|
def presence
|
19
19
|
self if fields.present? || associations.present?
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
# Adds a new field (json api notation) to the tree structure:
|
23
23
|
#
|
24
24
|
# user_tree.notation
|
@@ -33,7 +33,7 @@ module Fields
|
|
33
33
|
rest.present? ? add_association!(parent, rest) : add_field!(parent)
|
34
34
|
self
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
# Return the tree structure in Rails includes notation including both associations and fields
|
38
38
|
#
|
39
39
|
# user_tree.notation
|
@@ -64,13 +64,13 @@ module Fields
|
|
64
64
|
end.presence
|
65
65
|
Array.wrap(to_includes).one? ? to_includes.first : to_includes
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
def to_s
|
69
69
|
notation.to_s
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
private
|
73
|
-
|
73
|
+
|
74
74
|
def add_association!(parent, rest)
|
75
75
|
existing_association?(parent) ? merge_association!(parent, rest) : append_association!(parent, rest)
|
76
76
|
end
|
@@ -100,19 +100,19 @@ module Fields
|
|
100
100
|
end
|
101
101
|
|
102
102
|
def association?(value)
|
103
|
-
klass.reflections.
|
103
|
+
klass.reflections.key?(value)
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
def associations_to_notation
|
107
107
|
associations.inject({}) do |result, (k, v)|
|
108
108
|
result.merge!(k => v.notation)
|
109
109
|
end
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
def existing_association?(value)
|
113
113
|
!!associations[value]
|
114
114
|
end
|
115
|
-
|
115
|
+
|
116
116
|
def existing_field?(value)
|
117
117
|
fields.include?(value)
|
118
118
|
end
|
metadata
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fields-serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Stuart Chinery
|
8
|
-
- Miguel Montalbo
|
9
7
|
- Lorenzo Tello
|
10
8
|
autorequire:
|
11
9
|
bindir: exe
|
12
10
|
cert_chain: []
|
13
|
-
date: 2018-
|
11
|
+
date: 2018-08-16 00:00:00.000000000 Z
|
14
12
|
dependencies:
|
15
13
|
- !ruby/object:Gem::Dependency
|
16
14
|
name: bundler
|
@@ -55,7 +53,7 @@ dependencies:
|
|
55
53
|
- !ruby/object:Gem::Version
|
56
54
|
version: '3.6'
|
57
55
|
- !ruby/object:Gem::Dependency
|
58
|
-
name:
|
56
|
+
name: factory_bot
|
59
57
|
requirement: !ruby/object:Gem::Requirement
|
60
58
|
requirements:
|
61
59
|
- - "~>"
|
@@ -127,7 +125,7 @@ dependencies:
|
|
127
125
|
description: Extensions to ActiveRecord and ActionController to serialize a subset
|
128
126
|
of model fields
|
129
127
|
email:
|
130
|
-
-
|
128
|
+
- ltello8a@gmail.com
|
131
129
|
executables: []
|
132
130
|
extensions: []
|
133
131
|
extra_rdoc_files: []
|
@@ -168,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
166
|
version: '0'
|
169
167
|
requirements: []
|
170
168
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.6.
|
169
|
+
rubygems_version: 2.6.13
|
172
170
|
signing_key:
|
173
171
|
specification_version: 4
|
174
172
|
summary: Extensions to ActiveRecord and ActionController to serialize a subset of
|