media_types-serialization 0.3.2 → 0.4.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 +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +4 -3
- data/lib/media_types/serialization/base.rb +5 -6
- data/lib/media_types/serialization/version.rb +1 -1
- data/lib/media_types/serialization/wrapper/media_collection_wrapper.rb +8 -1
- data/lib/media_types/serialization/wrapper/media_index_wrapper.rb +8 -1
- data/lib/media_types/serialization/wrapper/media_object_wrapper.rb +7 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8bff701e51e128e250514cb3b951409907496d54ac1c9bbfdcea02c269d0c09
|
4
|
+
data.tar.gz: 519cf91eb85882e2f37b4a7f500025f96ce6551bda4798e2c4d9f8ca7d9813b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f69cb4908449138b1c0f6aa080df5ed9401d2ee344356199843ca92543c2c5b2539dbb2b7e4a342a8d583d7a6ac054f2e45c345a4a663178473cdc2a2bd25d1e
|
7
|
+
data.tar.gz: 95345bbf3f598c613926b2531496ee89a99c6bc16199bb025e033d9d065b4d34ab97efc63d03f43a12cf63e55ce8acb760f4ace0d8587e889ce2f5375d5ef060
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.4.0
|
4
|
+
|
5
|
+
- Change `extract_links` to `extract_links(view:)` and mimic `header_links(view:)`
|
6
|
+
- Use `extract_links` in `index` and `collection` wrapper output
|
7
|
+
|
3
8
|
## 0.3.2
|
4
9
|
|
5
10
|
- Rename `collect_links` to `header_links` to actually expose the links
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -60,9 +60,7 @@ class Book < ApplicationRecord
|
|
60
60
|
{ href: context.api_book_url(serializable) }
|
61
61
|
end
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
def extract_links
|
63
|
+
def extract_links(view:)
|
66
64
|
{
|
67
65
|
'self': extract_self,
|
68
66
|
'signatures': { href: context.api_book_signatures_url(serializable) }
|
@@ -217,6 +215,9 @@ if entries.present?
|
|
217
215
|
end
|
218
216
|
```
|
219
217
|
|
218
|
+
If you want the link header to be different from the `_links`, you can implement `header_links(view:)` next to
|
219
|
+
`extract_links(view:)`. This will be called by the `to_link_header` function.
|
220
|
+
|
220
221
|
### Related
|
221
222
|
|
222
223
|
- [`MediaTypes`](https://github.com/SleeplessByte/media-types-ruby): :gem: Library to create media type definitions, schemes and validations
|
@@ -60,19 +60,18 @@ module MediaTypes
|
|
60
60
|
super
|
61
61
|
end
|
62
62
|
|
63
|
+
def header_links(view: current_view)
|
64
|
+
extract_links(view: view)
|
65
|
+
end
|
66
|
+
|
63
67
|
protected
|
64
68
|
|
65
69
|
attr_accessor :context, :current_media_type, :current_view
|
66
70
|
|
67
|
-
def extract_links
|
71
|
+
def extract_links(view: current_view)
|
68
72
|
{}
|
69
73
|
end
|
70
74
|
|
71
|
-
# noinspection RubyUnusedLocalVariable
|
72
|
-
def header_links(view: current_view)
|
73
|
-
extract_links
|
74
|
-
end
|
75
|
-
|
76
75
|
def set(serializable)
|
77
76
|
self.serializable = serializable
|
78
77
|
self
|
@@ -22,7 +22,7 @@ module MediaTypes
|
|
22
22
|
def to_hash
|
23
23
|
{ Wrapper::RootKey.new(__getobj__.class).pluralize => {
|
24
24
|
'_embedded': auto_wrap_serializable.map(&method(:item_hash)),
|
25
|
-
'_links':
|
25
|
+
'_links': extract_links
|
26
26
|
} }
|
27
27
|
end
|
28
28
|
alias to_h to_hash
|
@@ -32,6 +32,13 @@ module MediaTypes
|
|
32
32
|
{}
|
33
33
|
end
|
34
34
|
|
35
|
+
protected
|
36
|
+
|
37
|
+
def extract_links(view: current_view)
|
38
|
+
return __getobj__.send(:extract_links, view: view) if serializable && ::MediaTypes::Serialization.collect_links_for_collection
|
39
|
+
{}
|
40
|
+
end
|
41
|
+
|
35
42
|
private
|
36
43
|
|
37
44
|
def auto_wrap_serializable
|
@@ -22,7 +22,7 @@ module MediaTypes
|
|
22
22
|
def to_hash
|
23
23
|
{ Wrapper::RootKey.new(__getobj__.class).pluralize => {
|
24
24
|
'_index': auto_wrap_serializable.map(&method(:item_hash)),
|
25
|
-
'_links':
|
25
|
+
'_links': extract_links
|
26
26
|
} }
|
27
27
|
end
|
28
28
|
alias to_h to_hash
|
@@ -32,6 +32,13 @@ module MediaTypes
|
|
32
32
|
{}
|
33
33
|
end
|
34
34
|
|
35
|
+
protected
|
36
|
+
|
37
|
+
def extract_links(view: current_view)
|
38
|
+
return __getobj__.send(:extract_links, view: view) if serializable && ::MediaTypes::Serialization.collect_links_for_index
|
39
|
+
{}
|
40
|
+
end
|
41
|
+
|
35
42
|
private
|
36
43
|
|
37
44
|
def auto_wrap_serializable
|
@@ -30,6 +30,13 @@ module MediaTypes
|
|
30
30
|
{}
|
31
31
|
end
|
32
32
|
|
33
|
+
protected
|
34
|
+
|
35
|
+
def extract_links(view: current_view)
|
36
|
+
return __getobj__.send(:extract_links, view: view) if serializable
|
37
|
+
{}
|
38
|
+
end
|
39
|
+
|
33
40
|
private
|
34
41
|
|
35
42
|
AUTO_UNWRAP_KLAZZES = [Array, defined?(ActiveRecord) ? ActiveRecord::Relation : nil].compact.freeze
|