jsonapi-serializable 0.1.1 → 0.1.2
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 +4 -4
- data/README.md +6 -0
- data/lib/jsonapi/serializable/error.rb +0 -1
- data/lib/jsonapi/serializable/renderer.rb +1 -1
- data/lib/jsonapi/serializable/resource/conditional_fields.rb +2 -2
- data/lib/jsonapi/serializable/resource/{key_transform.rb → key_format.rb} +7 -7
- data/lib/jsonapi/serializable/resource/type.rb +24 -9
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cb44ca89eb1b7e4d57963e58ee633a72286bf09
|
4
|
+
data.tar.gz: b58ecc0baa551e82c9a3d4de80d197d779c0c31b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 665e7c08b7c03d91db56c6bcf89d592e84618b6b8d00f41defb42c3cd42412938366d4e010c7cbd1d2680f70b24c1cd4377d9dfc5e7b06d6f78c292d22774de9
|
7
|
+
data.tar.gz: 4947189e22b7ea602475972030cdf332230a311a1f86289a44de542cb73bcbcbcfcc02ce01e42049fbba3eca72ce546f9dc80b4f63167a5ce11cacb098cf06dc
|
data/README.md
CHANGED
@@ -8,6 +8,12 @@ Ruby gem for building and rendering [JSON API](http://jsonapi.org) documents.
|
|
8
8
|
[](https://codecov.io/gh/jsonapi-rb/jsonapi-serializable)
|
9
9
|
[](https://gitter.im/jsonapi-rb/Lobby)
|
10
10
|
|
11
|
+
## Resources
|
12
|
+
|
13
|
+
* Chat: [gitter](http://gitter.im/jsonapi-rb)
|
14
|
+
* Twitter: [@jsonapirb](http://twitter.com/jsonapirb)
|
15
|
+
* Docs: [jsonapi-rb.org](http://jsonapi-rb.org)
|
16
|
+
|
11
17
|
## Installation
|
12
18
|
```ruby
|
13
19
|
# In Gemfile
|
@@ -14,7 +14,7 @@ module JSONAPI
|
|
14
14
|
module ConditionalFields
|
15
15
|
def self.prepended(klass)
|
16
16
|
klass.class_eval do
|
17
|
-
extend
|
17
|
+
extend DSL
|
18
18
|
class << self
|
19
19
|
attr_accessor :condition_blocks
|
20
20
|
end
|
@@ -23,7 +23,7 @@ module JSONAPI
|
|
23
23
|
end
|
24
24
|
|
25
25
|
# DSL extensions for conditional fields.
|
26
|
-
module
|
26
|
+
module DSL
|
27
27
|
def inherited(klass)
|
28
28
|
super
|
29
29
|
klass.condition_blocks = condition_blocks.dup
|
@@ -13,27 +13,27 @@ module JSONAPI
|
|
13
13
|
# has_many :close_friends
|
14
14
|
# end
|
15
15
|
# # => will modify the serialized keys to `UserName` and `CloseFriends`.
|
16
|
-
module
|
16
|
+
module KeyFormat
|
17
17
|
def self.prepended(klass)
|
18
18
|
klass.class_eval do
|
19
|
-
extend
|
19
|
+
extend DSL
|
20
20
|
class << self
|
21
|
-
attr_accessor :
|
21
|
+
attr_accessor :key_format
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
# DSL extensions for automatic key transformations.
|
27
|
-
module
|
27
|
+
module DSL
|
28
28
|
def inherited(klass)
|
29
29
|
super
|
30
|
-
klass.
|
30
|
+
klass.key_format = key_format
|
31
31
|
end
|
32
32
|
|
33
33
|
# Handles automatic key transformation for attributes.
|
34
34
|
def attribute(name, options = {}, &block)
|
35
35
|
block ||= proc { @object.public_send(name) }
|
36
|
-
super(
|
36
|
+
super(key_format.call(name), options, &block)
|
37
37
|
end
|
38
38
|
|
39
39
|
# Handles automatic key transformation for relationships.
|
@@ -42,7 +42,7 @@ module JSONAPI
|
|
42
42
|
data(options[:class]) { @object.public_send(name) }
|
43
43
|
instance_eval(&block) unless block.nil?
|
44
44
|
end
|
45
|
-
super(
|
45
|
+
super(key_format.call(name), options, &rel_block)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -8,14 +8,18 @@ module JSONAPI
|
|
8
8
|
klass.class_eval do
|
9
9
|
extend DSL
|
10
10
|
class << self
|
11
|
-
attr_accessor :type_val
|
11
|
+
attr_accessor :type_val, :type_block
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
def initialize(*)
|
17
17
|
super
|
18
|
-
@_type = self.class.
|
18
|
+
@_type = if self.class.type_block
|
19
|
+
instance_eval(&self.class.type_block).to_sym
|
20
|
+
else
|
21
|
+
self.class.type_val || :unknown
|
22
|
+
end
|
19
23
|
end
|
20
24
|
|
21
25
|
# @see JSONAPI::Serializable::Resource#as_jsonapi
|
@@ -29,16 +33,27 @@ module JSONAPI
|
|
29
33
|
module DSL
|
30
34
|
def inherited(klass)
|
31
35
|
super
|
32
|
-
klass.type_val
|
36
|
+
klass.type_val = type_val
|
37
|
+
klass.type_block = type_block
|
33
38
|
end
|
34
39
|
|
35
|
-
#
|
36
|
-
#
|
40
|
+
# @overload type(value)
|
41
|
+
# Declare the JSON API type of this resource.
|
42
|
+
# @param [String] value The value of the type.
|
37
43
|
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
|
41
|
-
|
44
|
+
# @example
|
45
|
+
# type 'users'
|
46
|
+
#
|
47
|
+
# @overload type(&block)
|
48
|
+
# Declare the JSON API type of this resource.
|
49
|
+
# @yieldreturn [String] The value of the type.
|
50
|
+
# @example
|
51
|
+
# type do
|
52
|
+
# @object.type
|
53
|
+
# end
|
54
|
+
def type(value = nil, &block)
|
55
|
+
self.type_val = value.to_sym if value
|
56
|
+
self.type_block = block
|
42
57
|
end
|
43
58
|
end
|
44
59
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-serializable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Hosseini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jsonapi-renderer
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.1
|
19
|
+
version: '0.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.1
|
26
|
+
version: '0.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -85,7 +85,7 @@ files:
|
|
85
85
|
- lib/jsonapi/serializable/resource/attributes.rb
|
86
86
|
- lib/jsonapi/serializable/resource/conditional_fields.rb
|
87
87
|
- lib/jsonapi/serializable/resource/id.rb
|
88
|
-
- lib/jsonapi/serializable/resource/
|
88
|
+
- lib/jsonapi/serializable/resource/key_format.rb
|
89
89
|
- lib/jsonapi/serializable/resource/links.rb
|
90
90
|
- lib/jsonapi/serializable/resource/meta.rb
|
91
91
|
- lib/jsonapi/serializable/resource/relationships.rb
|