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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47761a57539196c1be8d4de3b4f18a78a0e133bdace720e4363dfc2a4ab5776c
4
- data.tar.gz: caccc39b0926d5f39a29673a912fab356079fb67357b868cc4f803b325988890
3
+ metadata.gz: f191e5daf97acca13c721c2ddca506a38919433f2207d2cecb59433b463dbea7
4
+ data.tar.gz: 579ec81e38550f980c0e1fe96e2db9bcf50d4c99b2a52d48ab875a8970bc2c07
5
5
  SHA512:
6
- metadata.gz: d7ee0004606f84e64e0b94697d1ff035f54b96ceb3dddc1f0a77c716ad17c566b9b959f78a67cfa6c40598c337db4464c62c26d2d394a749183bec915cad3d44
7
- data.tar.gz: 6aecb9eb64b1bd282de2d29a3828fe131fa01227c50b8b5ff69049cb08184497435d9f67ab95f71dacf8120e072ff813b00dac497e81772396f249b0e8a74327
6
+ metadata.gz: b642637b676156b1e3f9783ceab09a5e9e8f6bf8ebf6c76e4c3ee292b95c59396bd62eb8ba6bf6ad296a5c5d116e3e25dc847a5c65da2ab7f2a443f482e6c3e5
7
+ data.tar.gz: 628ea27143c5ac74c97d141c67fbecedd99c51ac68f565d2677e15e250098848bb99c986e7d2f92809f09bd5008c1b41991d7c7f73bc97edc64b772f54fc494e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- decanter (3.5.0)
4
+ decanter (3.5.1)
5
5
  actionpack (>= 4.2.10)
6
6
  activesupport
7
7
  rails-html-sanitizer (>= 1.0.4)
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
@@ -57,7 +57,6 @@ end
57
57
 
58
58
  require 'decanter/version'
59
59
  require 'decanter/configuration'
60
- require 'decanter/core'
61
60
  require 'decanter/base'
62
61
  require 'decanter/extensions'
63
62
  require 'decanter/exceptions'
data/lib/decanter/base.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  require 'decanter/core'
2
+ require 'decanter/collection_detection'
2
3
 
3
4
  module Decanter
4
5
  class Base
5
6
  include Core
7
+ include CollectionDetection
6
8
  end
7
9
  end
@@ -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
@@ -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
- is_collection?(args, options[:is_collection]) ? decant_collection(args, options) : decant_args(args, options)
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
@@ -1,3 +1,3 @@
1
1
  module Decanter
2
- VERSION = '3.5.0'.freeze
2
+ VERSION = '3.5.1'.freeze
3
3
  end
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.0
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-01-23 00:00:00.000000000 Z
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