pragmatic_serializer 0.3.1 → 0.4.0

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
  SHA1:
3
- metadata.gz: f12aa45a3ed7366d2713012deb98b6090c4ac2f6
4
- data.tar.gz: 43c9dfa94e247474e2270ae1656cafcb8157cee9
3
+ metadata.gz: 358009ad79164256e989d1023de3df4159ab890a
4
+ data.tar.gz: 717e862876a3fec0f6f11a39db296a4b332442e8
5
5
  SHA512:
6
- metadata.gz: 379215fc4220f598c6f05c84237e3515d3c4bb7d34c1f9d600ad5b3b180685b4932d5f4154f9e87b9ee492cb3095567c86765203df017cca29e8a917b926c994
7
- data.tar.gz: 18a42d4c24d04dd09e3fd7d943c07852b6a781404c5b74af3af55ecaaefa396cfdaa6293e5e6dbe0483bea67452f2d6d20aec5197ac50f9eb14c8ede643f94e4
6
+ metadata.gz: 8ed3f9b3c44da8ce808f0e78e5c0fa7406b13c77970f27a0513669b9c7ce143259d3626bb31fe04b213669e325aa56d587ace5caa053c7ef2cec12eeff644bf3
7
+ data.tar.gz: 87c8b2b71017d6edef53f3903b64728c56a18cbe93f91a409f843d58affd18e5e7ff27d44fa82038508d9b1d626203ba368fc02e1ba25298f5f2f36efbe5c203
data/README.md CHANGED
@@ -79,6 +79,13 @@ policy = BandPolicy.new(current_user: current_user)
79
79
 
80
80
  serializer = MySerializer.collection([r1, r2], resource_options: { :"policy=" => policy })
81
81
  serializer.as_json
82
+
83
+
84
+ # OR
85
+
86
+ serializer = MySerializer.collection([r1, r2])
87
+ serializer.resource_options.policy = policy
88
+ serializer.as_json
82
89
  ```
83
90
 
84
91
  As regular user:
@@ -1,13 +1,39 @@
1
1
  module PragmaticSerializer
2
2
  class CollectionSerializer
3
+ class ResourceOptions
4
+ def _registered_method_pairs
5
+ @registered_method_pairs ||= []
6
+ end
7
+
8
+ def _call_each_reg_method_pair(obj)
9
+ _registered_method_pairs.each do |val|
10
+ obj.public_send(val[0], *val[1], &val[2])
11
+ end
12
+ end
13
+
14
+ def method_missing(method_name, *args, &block)
15
+ _registered_method_pairs << [method_name, args, block]
16
+ end
17
+ end
18
+
3
19
  OverMaximumLimit = Class.new(StandardError)
4
20
 
5
21
  extend Forwardable
6
22
  include PragmaticSerializer::ConfigInterface
7
23
 
8
- attr_writer :limit, :offset, :serialization_method, :resource_options
24
+ attr_writer :limit, :offset, :serialization_method
9
25
  attr_accessor :resources, :total, :resource_serializer, :pagination_evaluator
10
26
 
27
+ def resource_options
28
+ @resource_options ||= ResourceOptions.new
29
+ end
30
+
31
+ def resource_options=(**options)
32
+ options.each_pair do |method_name, value|
33
+ resource_options.send(method_name, value)
34
+ end
35
+ end
36
+
11
37
  def serialization_method
12
38
  @serialization_method ||= config.default_resource_serialization_method
13
39
  end
@@ -38,11 +64,7 @@ module PragmaticSerializer
38
64
  def collection_serializers
39
65
  resources.map do |resource|
40
66
  resource_object = resource_serializer.new(resource)
41
-
42
- resource_options.each do |method_name, value|
43
- resource_object.send(method_name, value)
44
- end
45
-
67
+ resource_options._call_each_reg_method_pair(resource_object)
46
68
  resource_object
47
69
  end
48
70
  end
@@ -55,9 +77,5 @@ module PragmaticSerializer
55
77
  pagination_evaluator: pagination_evaluator
56
78
  })
57
79
  end
58
-
59
- def resource_options
60
- @resource_options ||= {}
61
- end
62
80
  end
63
81
  end
@@ -1,3 +1,3 @@
1
1
  module PragmaticSerializer
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'forwardable'
2
+ require 'ostruct'
2
3
  require 'active_support/core_ext/string/inflections'
3
4
 
4
5
  require "pragmatic_serializer/version"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pragmatic_serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Valent
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-07 00:00:00.000000000 Z
11
+ date: 2018-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  version: '0'
119
119
  requirements: []
120
120
  rubyforge_project:
121
- rubygems_version: 2.5.1
121
+ rubygems_version: 2.6.11
122
122
  signing_key:
123
123
  specification_version: 4
124
124
  summary: JSON API serializer following Pragmatic JSON standard