media_types-serialization 0.5.0 → 0.5.1
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/.idea/media_types-serialization.iml +1 -1
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +15 -1
- data/lib/media_types/serialization/base.rb +8 -7
- data/lib/media_types/serialization/version.rb +1 -1
- data/lib/media_types/serialization/wrapper/html_wrapper.rb +0 -2
- data/lib/media_types/serialization/wrapper/media_collection_wrapper.rb +2 -8
- data/lib/media_types/serialization/wrapper/media_index_wrapper.rb +1 -7
- data/lib/media_types/serialization/wrapper/media_object_wrapper.rb +1 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d52037ca66b6864b8f20026b58fef6053f12ad870d9e6c2557395244b820d2a
|
4
|
+
data.tar.gz: 0c01cedd3e14c127a791aeedd78e8674a9fefabd1e3d7768921bbb731ce93c85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21aecc3516b00a3dcd9c02ac1389211858dedbb1e38876f0416c0fe03e69f76e213e20c282b564b52053fb6f81d71ee3af8091bdf0e371fd65efc01f958be762
|
7
|
+
data.tar.gz: 772be730a9c94e6ab4201f7ddc11daebfbae8a9368185d2ce5d5a0e6c2e43d13f368bcf2071c4b62ead4b714f4559986066455a7cab3b75eab2f4bbe7bdcaf0e
|
@@ -37,7 +37,7 @@
|
|
37
37
|
<orderEntry type="library" scope="PROVIDED" name="http_headers-accept (v0.2.1, ruby-2.5.3-p105) [gem]" level="application" />
|
38
38
|
<orderEntry type="library" scope="PROVIDED" name="http_headers-link (v0.2.1, ruby-2.5.3-p105) [gem]" level="application" />
|
39
39
|
<orderEntry type="library" scope="PROVIDED" name="http_headers-utils (v0.2.0, ruby-2.5.3-p105) [gem]" level="application" />
|
40
|
-
<orderEntry type="library" scope="PROVIDED" name="i18n (v1.
|
40
|
+
<orderEntry type="library" scope="PROVIDED" name="i18n (v1.6.0, ruby-2.5.3-p105) [gem]" level="application" />
|
41
41
|
<orderEntry type="library" scope="PROVIDED" name="loofah (v2.2.3, ruby-2.5.3-p105) [gem]" level="application" />
|
42
42
|
<orderEntry type="library" scope="PROVIDED" name="media_types (v0.6.0, ruby-2.5.3-p105) [gem]" level="application" />
|
43
43
|
<orderEntry type="library" scope="PROVIDED" name="mini_portile2 (v2.4.0, ruby-2.5.3-p105) [gem]" level="application" />
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -196,13 +196,27 @@ class Book::CoverHtmlSerializer < MediaTypes::Serialization::Base
|
|
196
196
|
end
|
197
197
|
```
|
198
198
|
|
199
|
+
You can change the default `wrapper` / `to_html` implementation by setting:
|
200
|
+
```ruby
|
201
|
+
::MediaTypes::Serialization.html_wrapper_layout = '/path/to/wrapper/layout'
|
202
|
+
```
|
203
|
+
|
199
204
|
### Wrapping output
|
200
205
|
|
201
206
|
By convention, `index` views are wrapped in `_index: [items]`, `collection` views are wrapped in `_embedded: [items]`
|
202
207
|
and `create` / no views are wrapped in `[ROOT_KEY]: item`. This is currently only enabled for `to_json` serialization
|
203
208
|
but planned for `xml` as well.
|
204
209
|
|
205
|
-
This behaviour can not be turned of as of writing.
|
210
|
+
This behaviour can not be turned of as of writing. However, you may _overwrite_ this behaviour via:
|
211
|
+
|
212
|
+
- `self.root_key(view:)`: to define the root key for a specific `view`
|
213
|
+
- `self.wrap(serializer, view: nil)`: to define the wrapper for a specific `view` and/or `serializer`. For example, if
|
214
|
+
you never want to wrap anything, you could define:
|
215
|
+
```ruby
|
216
|
+
def self.wrap(serializer, view: nil)
|
217
|
+
serializer
|
218
|
+
end
|
219
|
+
```
|
206
220
|
|
207
221
|
### Link header
|
208
222
|
|
@@ -16,7 +16,7 @@ module MediaTypes
|
|
16
16
|
include MigrationsSupport
|
17
17
|
include WrapperSupport
|
18
18
|
|
19
|
-
|
19
|
+
attr_reader :current_media_type, :current_view, :serializable
|
20
20
|
|
21
21
|
def initialize(serializable, media_type:, view: nil, context:)
|
22
22
|
self.context = context
|
@@ -68,19 +68,20 @@ module MediaTypes
|
|
68
68
|
extract_links(view: view)
|
69
69
|
end
|
70
70
|
|
71
|
+
def set(serializable)
|
72
|
+
self.serializable = serializable
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
71
76
|
protected
|
72
77
|
|
73
|
-
attr_accessor :context
|
78
|
+
attr_accessor :context
|
79
|
+
attr_writer :current_media_type, :current_view, :serializable
|
74
80
|
|
75
81
|
def extract_links(view: current_view)
|
76
82
|
{}
|
77
83
|
end
|
78
84
|
|
79
|
-
def set(serializable)
|
80
|
-
self.serializable = serializable
|
81
|
-
self
|
82
|
-
end
|
83
|
-
|
84
85
|
def extract(extractable, *keys)
|
85
86
|
return {} unless keys.present?
|
86
87
|
extractable.slice(*keys)
|
@@ -4,15 +4,13 @@ require 'delegate'
|
|
4
4
|
|
5
5
|
require 'active_support/core_ext/string/inflections'
|
6
6
|
|
7
|
-
require 'media_types/serialization/base'
|
8
|
-
|
9
7
|
module MediaTypes
|
10
8
|
module Serialization
|
11
9
|
module Wrapper
|
12
10
|
class MediaCollectionWrapper < SimpleDelegator
|
13
11
|
|
14
12
|
delegate :to_json, to: :to_hash
|
15
|
-
delegate :class, to: :__getobj__
|
13
|
+
delegate :class, :set, :current_view, :current_media_type, to: :__getobj__
|
16
14
|
|
17
15
|
def initialize(serializer)
|
18
16
|
__setobj__ serializer
|
@@ -48,17 +46,13 @@ module MediaTypes
|
|
48
46
|
|
49
47
|
def item_hash(item)
|
50
48
|
__getobj__.instance_exec do
|
51
|
-
set(item).
|
49
|
+
set(item).to_hash
|
52
50
|
end
|
53
51
|
end
|
54
52
|
|
55
53
|
def root_key(view: current_view)
|
56
54
|
__getobj__.class.root_key(view: view)
|
57
55
|
end
|
58
|
-
|
59
|
-
def current_view
|
60
|
-
__getobj__.send(:current_view)
|
61
|
-
end
|
62
56
|
end
|
63
57
|
end
|
64
58
|
end
|
@@ -4,15 +4,13 @@ require 'delegate'
|
|
4
4
|
|
5
5
|
require 'active_support/core_ext/string/inflections'
|
6
6
|
|
7
|
-
require 'media_types/serialization/base'
|
8
|
-
|
9
7
|
module MediaTypes
|
10
8
|
module Serialization
|
11
9
|
module Wrapper
|
12
10
|
class MediaIndexWrapper < SimpleDelegator
|
13
11
|
|
14
12
|
delegate :to_json, to: :to_hash
|
15
|
-
delegate :class, to: :__getobj__
|
13
|
+
delegate :class, :set, :current_view, :current_media_type, to: :__getobj__
|
16
14
|
|
17
15
|
def initialize(serializer)
|
18
16
|
__setobj__ serializer
|
@@ -55,10 +53,6 @@ module MediaTypes
|
|
55
53
|
def root_key(view: current_view)
|
56
54
|
__getobj__.class.root_key(view: view)
|
57
55
|
end
|
58
|
-
|
59
|
-
def current_view
|
60
|
-
__getobj__.send(:current_view)
|
61
|
-
end
|
62
56
|
end
|
63
57
|
end
|
64
58
|
end
|
@@ -4,15 +4,13 @@ require 'delegate'
|
|
4
4
|
|
5
5
|
require 'active_support/core_ext/string/inflections'
|
6
6
|
|
7
|
-
require 'media_types/serialization/base'
|
8
|
-
|
9
7
|
module MediaTypes
|
10
8
|
module Serialization
|
11
9
|
module Wrapper
|
12
10
|
class MediaObjectWrapper < SimpleDelegator
|
13
11
|
|
14
12
|
delegate :to_json, to: :to_hash
|
15
|
-
delegate :class, to: :__getobj__
|
13
|
+
delegate :class, :set, :current_view, :current_media_type, to: :__getobj__
|
16
14
|
|
17
15
|
mattr_accessor :auto_unwrap_klazzes
|
18
16
|
|
@@ -51,14 +49,6 @@ module MediaTypes
|
|
51
49
|
def root_key(view: current_view)
|
52
50
|
__getobj__.class.root_key(view: view)
|
53
51
|
end
|
54
|
-
|
55
|
-
def set(new_serializable)
|
56
|
-
__getobj__.send(:set, new_serializable)
|
57
|
-
end
|
58
|
-
|
59
|
-
def current_view
|
60
|
-
__getobj__.send(:current_view)
|
61
|
-
end
|
62
52
|
end
|
63
53
|
end
|
64
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: media_types-serialization
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derk-Jan Karrenbeld
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|