media_types-serialization 0.5.0 → 0.5.1

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: 0c7c8556cbaffc26158c2b8b0cadef6e1544f532a47e03d6580b9518416240f2
4
- data.tar.gz: 49a6897feba02f920cce9d32ee6b4ea4f5838446404ce2bdf1d08b52ba4f1ef5
3
+ metadata.gz: 5d52037ca66b6864b8f20026b58fef6053f12ad870d9e6c2557395244b820d2a
4
+ data.tar.gz: 0c01cedd3e14c127a791aeedd78e8674a9fefabd1e3d7768921bbb731ce93c85
5
5
  SHA512:
6
- metadata.gz: 2400a94296b4f57e386b1a7b115511873ed449b58a8148b0bc64114942a5720db2270af8f1d7878e284aa6b2c58f713b0f7dd6ba297278132f7f496e18aaa2b7
7
- data.tar.gz: d93e89709b0d19111b6d3e0cfc1608fc386611ae80132df228af8c27ed43b30f4a739963b5d492e24184e83db4f86baac001834b30a0297e53577ce662f42c7c
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.5.3, ruby-2.5.3-p105) [gem]" level="application" />
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
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.1
4
+
5
+ - Correctly expose `current_media_type` and `current_view`
6
+ - Fix cyclic requires
7
+ - Add documentation for overwriting wrappers
8
+
3
9
  ## 0.5.0
4
10
 
5
11
  - Change wrappers to extend from `SimpleDelegator`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- media_types-serialization (0.5.0)
4
+ media_types-serialization (0.5.1)
5
5
  actionpack (>= 4.0.0)
6
6
  activesupport (>= 4.0.0)
7
7
  http_headers-accept (< 1.0.0)
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
- attr_accessor :serializable
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, :current_media_type, :current_view
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)
@@ -1,5 +1,5 @@
1
1
  module MediaTypes
2
2
  module Serialization
3
- VERSION = '0.5.0'
3
+ VERSION = '0.5.1'
4
4
  end
5
5
  end
@@ -4,8 +4,6 @@ require 'delegate'
4
4
 
5
5
  require 'action_controller'
6
6
 
7
- require 'media_types/serialization/base'
8
-
9
7
  module MediaTypes
10
8
  module Serialization
11
9
  module Wrapper
@@ -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).send(:to_hash)
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.0
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-05 00:00:00.000000000 Z
11
+ date: 2019-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack