decanter 3.5.0 → 3.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/lib/decanter.rb +0 -1
- data/lib/decanter/base.rb +2 -0
- data/lib/decanter/collection_detection.rb +26 -0
- data/lib/decanter/extensions.rb +2 -19
- data/lib/decanter/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f191e5daf97acca13c721c2ddca506a38919433f2207d2cecb59433b463dbea7
|
4
|
+
data.tar.gz: 579ec81e38550f980c0e1fe96e2db9bcf50d4c99b2a52d48ab875a8970bc2c07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b642637b676156b1e3f9783ceab09a5e9e8f6bf8ebf6c76e4c3ee292b95c59396bd62eb8ba6bf6ad296a5c5d116e3e25dc847a5c65da2ab7f2a443f482e6c3e5
|
7
|
+
data.tar.gz: 628ea27143c5ac74c97d141c67fbecedd99c51ac68f565d2677e15e250098848bb99c986e7d2f92809f09bd5008c1b41991d7c7f73bc97edc64b772f54fc494e
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -101,6 +101,7 @@ If this option is not provided, autodetect logic is used to determine if the pro
|
|
101
101
|
- `nil` or not provided: will try to autodetect single vs collection
|
102
102
|
- `true` will always treat the incoming params args as *collection*
|
103
103
|
- `false` will always treat incoming params args as *single object*
|
104
|
+
- `truthy` will raise an error
|
104
105
|
|
105
106
|
### Nested resources
|
106
107
|
|
data/lib/decanter.rb
CHANGED
data/lib/decanter/base.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Decanter
|
2
|
+
module CollectionDetection
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def decant(args, **options)
|
9
|
+
return super(args) unless collection?(args, options[:is_collection])
|
10
|
+
|
11
|
+
args.map { |resource| super(resource) }
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
# leveraging the approach used in the [fast JSON API gem](https://github.com/Netflix/fast_jsonapi#collection-serialization)
|
17
|
+
def collection?(args, collection_option = nil)
|
18
|
+
raise(ArgumentError, "#{name}: Unknown collection option value: #{collection_option}") unless [true, false, nil].include? collection_option
|
19
|
+
|
20
|
+
return collection_option unless collection_option.nil?
|
21
|
+
|
22
|
+
args.respond_to?(:size) && !args.respond_to?(:each_pair)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/decanter/extensions.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Decanter
|
2
2
|
module Extensions
|
3
|
-
|
4
3
|
def self.included(base)
|
5
4
|
base.extend(ClassMethods)
|
6
5
|
end
|
@@ -34,29 +33,13 @@ module Decanter
|
|
34
33
|
.save!(context: options[:context])
|
35
34
|
end
|
36
35
|
|
37
|
-
def decant(args, options={})
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
def decant_collection(args, options)
|
42
|
-
args.map { |resource| decant_args(resource, options) }
|
43
|
-
end
|
44
|
-
|
45
|
-
def decant_args(args, options)
|
46
|
-
if specified_decanter = options[:decanter]
|
36
|
+
def decant(args, options = {})
|
37
|
+
if (specified_decanter = options[:decanter])
|
47
38
|
Decanter.decanter_from(specified_decanter)
|
48
39
|
else
|
49
40
|
Decanter.decanter_for(self)
|
50
41
|
end.decant(args)
|
51
42
|
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
# leveraging the approach used in the [fast JSON API gem](https://github.com/Netflix/fast_jsonapi#collection-serialization)
|
56
|
-
def is_collection?(args, collection_option=nil)
|
57
|
-
return collection_option[:is_collection] unless collection_option.nil?
|
58
|
-
args.respond_to?(:size) && !args.respond_to?(:each_pair)
|
59
|
-
end
|
60
43
|
end
|
61
44
|
|
62
45
|
module ActiveRecordExtensions
|
data/lib/decanter/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decanter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.5.
|
4
|
+
version: 3.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Francis
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-04-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- decanter.gemspec
|
153
153
|
- lib/decanter.rb
|
154
154
|
- lib/decanter/base.rb
|
155
|
+
- lib/decanter/collection_detection.rb
|
155
156
|
- lib/decanter/configuration.rb
|
156
157
|
- lib/decanter/core.rb
|
157
158
|
- lib/decanter/exceptions.rb
|