plucker_serializer 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/plucker/base.rb +6 -6
- data/lib/plucker/collection.rb +17 -18
- data/lib/plucker/descriptor.rb +2 -2
- data/lib/plucker/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af8283b8fb399c77763762271db9ee9e01c7cb67a6c1d65076bd76761b81c779
|
4
|
+
data.tar.gz: c0e79765da235b4cec454375c967ed85e0483d74a3403e8a11a8c7b30e916e00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7acb91c9ec72c63fa5bce5f0d3d5c08979478caf08235efd7abefdf674ce146dd1f9ad7179fb6d40ac9ed4e67c9f152c10d8532dd338ec1b94374f675e6fd9c
|
7
|
+
data.tar.gz: fb0c12340759e5d09ccf56f3cbe49c04c112d6d219166de5004b1c241408788cfff8648053b2853b6c8689c15efd7f04e70ac9b37ee44e91ded5a705da752062
|
data/lib/plucker/base.rb
CHANGED
@@ -38,19 +38,19 @@ module Plucker
|
|
38
38
|
alias to_hash serializable_hash
|
39
39
|
alias to_h serializable_hash
|
40
40
|
|
41
|
-
def
|
42
|
-
|
41
|
+
def as_json(options = nil)
|
42
|
+
serializable_hash
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
46
|
-
|
45
|
+
def get_hash
|
46
|
+
attributes_hash.merge! associations_hash
|
47
47
|
end
|
48
48
|
|
49
49
|
def associations_hash
|
50
50
|
hash = {}
|
51
51
|
self.class._descriptor._relationships.each do |(key, relationship)|
|
52
52
|
next if relationship.excluded?(self)
|
53
|
-
hash[key] = relationship.value(self)
|
53
|
+
hash[key.to_s] = relationship.value(self)
|
54
54
|
end
|
55
55
|
hash
|
56
56
|
end
|
@@ -58,7 +58,7 @@ module Plucker
|
|
58
58
|
def attributes_hash
|
59
59
|
self.class._descriptor._attributes.each_with_object({}) do |(key, attr), hash|
|
60
60
|
next if attr.excluded?(self)
|
61
|
-
hash[key] = attr.value(self)
|
61
|
+
hash[key.to_s] = attr.value(self)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
data/lib/plucker/collection.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require_relative 'concerns/caching'
|
3
|
+
require "pluck_all"
|
3
4
|
|
4
5
|
module Plucker
|
5
6
|
class Collection
|
@@ -22,22 +23,10 @@ module Plucker
|
|
22
23
|
else
|
23
24
|
if serializer_class.cache_enabled?
|
24
25
|
fetch do
|
25
|
-
|
26
|
-
associated_hash
|
27
|
-
else
|
28
|
-
objects.map do |object|
|
29
|
-
serializer_class.new(object).serializable_hash
|
30
|
-
end.compact
|
31
|
-
end
|
26
|
+
get_hash
|
32
27
|
end
|
33
28
|
else
|
34
|
-
|
35
|
-
associated_hash
|
36
|
-
else
|
37
|
-
objects.map do |object|
|
38
|
-
serializer_class.new(object).serializable_hash
|
39
|
-
end.compact
|
40
|
-
end
|
29
|
+
get_hash
|
41
30
|
end
|
42
31
|
end
|
43
32
|
end
|
@@ -45,7 +34,17 @@ module Plucker
|
|
45
34
|
alias to_h serializable_hash
|
46
35
|
|
47
36
|
def as_json(options = nil)
|
48
|
-
|
37
|
+
serializable_hash
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_hash
|
41
|
+
if serializer_class.is_pluckable?
|
42
|
+
associated_hash
|
43
|
+
else
|
44
|
+
objects.map do |object|
|
45
|
+
serializer_class.new(object).serializable_hash
|
46
|
+
end.compact
|
47
|
+
end
|
49
48
|
end
|
50
49
|
|
51
50
|
def cache_version
|
@@ -63,9 +62,9 @@ module Plucker
|
|
63
62
|
pluck_to_hash(objects, serializer_class.pluckable_columns.to_a)
|
64
63
|
end
|
65
64
|
|
66
|
-
def pluck_to_hash(
|
67
|
-
namespaced_attrs = attrs.map { |attr|
|
68
|
-
|
65
|
+
def pluck_to_hash(objects, attrs)
|
66
|
+
namespaced_attrs = attrs.map { |attr| objects.model.table_name.to_s + "." + attr.to_s }
|
67
|
+
objects.pluck_all(namespaced_attrs.join(','))
|
69
68
|
end
|
70
69
|
|
71
70
|
def get_serialized_model(objects)
|
data/lib/plucker/descriptor.rb
CHANGED
@@ -7,12 +7,12 @@ module Plucker
|
|
7
7
|
self._serialized_model = get_serialized_model(serializer_class)
|
8
8
|
self._attributes = {}
|
9
9
|
self._relationships = {}
|
10
|
-
self._pluckable_columns = Set.new
|
10
|
+
self._pluckable_columns = Set.new
|
11
11
|
self._is_pluckable = true
|
12
12
|
end
|
13
13
|
|
14
14
|
def is_pluckable?
|
15
|
-
self._is_pluckable
|
15
|
+
self._is_pluckable
|
16
16
|
end
|
17
17
|
|
18
18
|
def add_attribute(key, attr)
|
data/lib/plucker/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plucker_serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henry Boisgibault
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pluck_all
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: A blazing fast JSON serializer for ActiveRecord & Ruby objects
|
28
42
|
email: henry@logora.fr
|
29
43
|
executables: []
|