jsonapi-serializable 0.1.2 → 0.1.3

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: 4cb44ca89eb1b7e4d57963e58ee633a72286bf09
4
- data.tar.gz: b58ecc0baa551e82c9a3d4de80d197d779c0c31b
3
+ metadata.gz: f59f8e3e6a7affd39f462919816e0931c277699e
4
+ data.tar.gz: 11647e5104f611adafd09c25e3c81d1b3c26d2f4
5
5
  SHA512:
6
- metadata.gz: 665e7c08b7c03d91db56c6bcf89d592e84618b6b8d00f41defb42c3cd42412938366d4e010c7cbd1d2680f70b24c1cd4377d9dfc5e7b06d6f78c292d22774de9
7
- data.tar.gz: 4947189e22b7ea602475972030cdf332230a311a1f86289a44de542cb73bcbcbcfcc02ce01e42049fbba3eca72ce546f9dc80b4f63167a5ce11cacb098cf06dc
6
+ metadata.gz: 104a61271b884fd79e98308850ee6943c14a195171cccfb00f77a4cd3faeeea38eae0665bb11403bec1674ac5c3b9ee8315552d3cbc611c7df5dbfe949ed7dbe
7
+ data.tar.gz: 9e840331b935f596a62f1b15fca6e66e74810a0db04d0cde0796bf0ef0cdb80ebba5643995de26bb44f68e58e5bf34d627c486583393b5e7dbdd61fd19704815
@@ -13,9 +13,11 @@ module JSONAPI
13
13
  @options = options.dup
14
14
  @klass = @options.delete(:class)
15
15
  @namespace = @options.delete(:namespace)
16
- @inferrer = @options.delete(:inferrer)
16
+ @inferrer = @options.delete(:inferrer) || namespace_inferrer
17
17
  @exposures = @options.delete(:expose) || {}
18
- @exposures[:_resource_inferrer] = namespace_inferrer || @inferrer
18
+ @exposures[:_resource_inferrer] = @inferrer
19
+
20
+ freeze
19
21
  end
20
22
 
21
23
  def render
@@ -40,10 +42,10 @@ module JSONAPI
40
42
  # @api private
41
43
  def namespace_inferrer
42
44
  return nil unless @namespace
43
- proc do |klass|
44
- names = klass.name.split('::')
45
+ proc do |class_name|
46
+ names = class_name.split('::')
45
47
  klass = names.pop
46
- [@namespace, names, "Serializable#{klass}"].reject(&:nil?).join('::')
48
+ [@namespace, *names, "Serializable#{klass}"].reject(&:nil?).join('::')
47
49
  end
48
50
  end
49
51
  end
@@ -1,13 +1,13 @@
1
1
  module JSONAPI
2
2
  module Serializable
3
3
  class Resource
4
- # Extension for handling automatic key transformations of
4
+ # Extension for handling automatic key formatting of
5
5
  # attributes/relationships.
6
6
  #
7
7
  # @usage
8
8
  # class SerializableUser < JSONAPI::Serializable::Resource
9
- # prepend JSONAPI::Serializable::Resource::KeyTransform
10
- # self.key_transform = proc { |key| key.camelize }
9
+ # prepend JSONAPI::Serializable::Resource::KeyFormat
10
+ # self.key_format = proc { |key| key.camelize }
11
11
  #
12
12
  # attribute :user_name
13
13
  # has_many :close_friends
@@ -23,20 +23,20 @@ module JSONAPI
23
23
  end
24
24
  end
25
25
 
26
- # DSL extensions for automatic key transformations.
26
+ # DSL extensions for automatic key formatting.
27
27
  module DSL
28
28
  def inherited(klass)
29
29
  super
30
30
  klass.key_format = key_format
31
31
  end
32
32
 
33
- # Handles automatic key transformation for attributes.
33
+ # Handles automatic key formatting for attributes.
34
34
  def attribute(name, options = {}, &block)
35
35
  block ||= proc { @object.public_send(name) }
36
36
  super(key_format.call(name), options, &block)
37
37
  end
38
38
 
39
- # Handles automatic key transformation for relationships.
39
+ # Handles automatic key formatting for relationships.
40
40
  def relationship(name, options = {}, &block)
41
41
  rel_block = proc do
42
42
  data(options[:class]) { @object.public_send(name) }
@@ -44,6 +44,12 @@ module JSONAPI
44
44
  end
45
45
  super(key_format.call(name), options, &rel_block)
46
46
  end
47
+
48
+ # NOTE(beauby): Re-aliasing those is necessary for the
49
+ # overridden `#relationship` method to be called.
50
+ alias has_many relationship
51
+ alias has_one relationship
52
+ alias belongs_to relationship
47
53
  end
48
54
  end
49
55
  end
@@ -0,0 +1,13 @@
1
+ module JSONAPI
2
+ module Serializable
3
+ class Resource
4
+ module TempId
5
+ def as_jsonapi(*)
6
+ super.tap do |hash|
7
+ hash[:'temp-id'] = @object.temp_id if @object.respond_to?(:temp_id)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
File without changes
@@ -5,6 +5,9 @@ require 'jsonapi/serializable/resource/links'
5
5
  require 'jsonapi/serializable/resource/attributes'
6
6
  require 'jsonapi/serializable/resource/relationships'
7
7
 
8
+ require 'jsonapi/serializable/resource/conditional_fields'
9
+ require 'jsonapi/serializable/resource/key_format'
10
+
8
11
  module JSONAPI
9
12
  module Serializable
10
13
  class Resource
@@ -18,8 +18,8 @@ module JSONAPI
18
18
  return objects if objects.nil? ||
19
19
  Array(objects).first.respond_to?(:as_jsonapi)
20
20
 
21
- if objects.respond_to?(:each)
22
- objects.map { |obj| new(obj, expose, klass).resource }
21
+ if objects.respond_to?(:to_ary)
22
+ Array(objects).map { |obj| new(obj, expose, klass).resource }
23
23
  else
24
24
  new(objects, expose, klass).resource
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi-serializable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Hosseini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-23 00:00:00.000000000 Z
11
+ date: 2017-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-renderer
@@ -89,6 +89,8 @@ files:
89
89
  - lib/jsonapi/serializable/resource/links.rb
90
90
  - lib/jsonapi/serializable/resource/meta.rb
91
91
  - lib/jsonapi/serializable/resource/relationships.rb
92
+ - lib/jsonapi/serializable/resource/temp_id.rb
93
+ - lib/jsonapi/serializable/resource/temp_id.rb~
92
94
  - lib/jsonapi/serializable/resource/type.rb
93
95
  - lib/jsonapi/serializable/resource_builder.rb
94
96
  homepage: https://github.com/jsonapi-rb/jsonapi-serializable