media_types-serialization 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad21aa89e0b5f448619f80f72462476021515c16c95d50dc269b2a8aa889ca45
4
- data.tar.gz: d723be10de6a6eecdb3b5b7e540db46b02ca0b5f338961bd0973ffaa957e7fe8
3
+ metadata.gz: d8bff701e51e128e250514cb3b951409907496d54ac1c9bbfdcea02c269d0c09
4
+ data.tar.gz: 519cf91eb85882e2f37b4a7f500025f96ce6551bda4798e2c4d9f8ca7d9813b4
5
5
  SHA512:
6
- metadata.gz: 612498a254d26d0288fcd035fbf18e6a84c9522069885fc30edba8898a3abc300716a2fd371d840fa65a688a9a089823d93b3aadc109e93ca052aa86d8299525
7
- data.tar.gz: cffa94a6a3de91e71f75bd84eb7c30b8090dfdf45e179302ed2d479dea99038deee36c002af48d1a7ad7a9eeaf070a16171a92dfe6b0eb9cbf804ee6f9562f32
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- media_types-serialization (0.3.2)
4
+ media_types-serialization (0.4.0)
5
5
  actionpack (>= 4.0.0)
6
6
  activesupport (>= 4.0.0)
7
7
  http_headers-accept (< 1.0.0)
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
- private
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
@@ -1,5 +1,5 @@
1
1
  module MediaTypes
2
2
  module Serialization
3
- VERSION = '0.3.2'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: media_types-serialization
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derk-Jan Karrenbeld