simple-json-api-serializer 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26aca00f45d33183b7dd675cb65cc5c0de391c23
4
- data.tar.gz: 8a10856e79d6c6190bd9834a50a8f7d3b6b12356
3
+ metadata.gz: 5ba77670aea7fe65f45dd044dd16de898d538b57
4
+ data.tar.gz: 6b3e6626f0a06154cfe61d992f63cd932593860f
5
5
  SHA512:
6
- metadata.gz: 8c017a9d09bee70bdeee9bd188734b8e23a082ee32f67d61fb785f4e620a45ce50b5eb84feb59f4a0ba5218748fd5d7a9712f4d0b8cf12cb75b469a1c0507123
7
- data.tar.gz: 49970b68ac24fcc874013197ede703328a02e7dc366cce35ac79d721f2d3738bfe30bc7f9846e10322b4ecd0ac98abce899c83bb826ec9e0c6440ce86b425631
6
+ metadata.gz: 203f943f6ba18beb7b1a79a27b4507251f811aeca62bf2b1bc03fa1f30ead13ace20544ee051d502f7f6712649fb293b7b2d3e1235cd8c10da933270aad813a4
7
+ data.tar.gz: 9f8f084339a487a9c3cfb3a64861b333461d21c31386017700e796b1854599db992a4f2c8f1f7e1a9eb57cfeef05ba1dba74e66a879dff34a73a17f0987a1265
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple-json-api-serializer (0.1.0)
4
+ simple-json-api-serializer (0.3.0)
5
5
  activesupport (~> 4.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (4.2.4)
10
+ activesupport (4.2.3)
11
11
  i18n (~> 0.7)
12
12
  json (~> 1.7, >= 1.7.7)
13
13
  minitest (~> 5.1)
@@ -6,13 +6,17 @@ require 'json_api/relationship_serializer'
6
6
  module JSONApi
7
7
  class ObjectSerializer
8
8
  def serialize(object, **options)
9
+ ActiveSupport::JSON.encode(hashify(object, **options))
10
+ end
11
+
12
+ def hashify(object, **options)
9
13
  hash = { data: data_for(object, **options) }
10
14
 
11
15
  if options[:include].is_a?(Array)
12
16
  hash[:included] = options[:include]
13
17
  end
14
18
 
15
- ActiveSupport::JSON.encode(hash)
19
+ hash
16
20
  end
17
21
 
18
22
  private
@@ -4,13 +4,15 @@ module JSONApi
4
4
  class ObjectSerializerDefinition
5
5
  class << self
6
6
  def serialize(object, **options)
7
- options[:id_attribute] ||= id_attribute
8
- options[:attributes] ||= attributes
9
- options[:relationships] ||= relationships
10
-
7
+ options = merge_options(**options)
11
8
  ObjectSerializer.new.serialize(object, **options)
12
9
  end
13
10
 
11
+ def hashify(object, **options)
12
+ options = merge_options(**options)
13
+ ObjectSerializer.new.hashify(object, **options)
14
+ end
15
+
14
16
  def inherited(specialization)
15
17
  specialization.attributes(*attributes)
16
18
  specialization.relationships(*relationships)
@@ -45,6 +47,15 @@ module JSONApi
45
47
  config[:to] = :many
46
48
  relationship(name, config)
47
49
  end
50
+
51
+ private
52
+
53
+ def merge_options(**options)
54
+ options[:id_attribute] ||= id_attribute
55
+ options[:attributes] ||= attributes
56
+ options[:relationships] ||= relationships
57
+ options
58
+ end
48
59
  end
49
60
  end
50
61
  end
@@ -1,3 +1,3 @@
1
1
  module JSONApi
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-json-api-serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marten Schilstra