hal_presenter 1.6.0 → 1.7.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: af641721e6b137d280c31c60efc6b76e7e1a22dd441a9b65aee3b929954290ec
4
- data.tar.gz: 784293b830aeed98f2f1ac1157b0526a8febe8ccbbe40a54dcee85acb8111294
3
+ metadata.gz: 0d44a7bd34475ea7e7187811e8e3d4447430835e6327440a714315477b8307f2
4
+ data.tar.gz: fa9bede97a583685589e2cea815be591bbb90c45034baf4697717fb06adc5f2d
5
5
  SHA512:
6
- metadata.gz: 829846a3e6a6d86e537817585ccfdc929efc758cf9a748b73c4a9c5d54d0760f8735301a7606a90d6279c2dba9efd1b3b9998a646c336a1656628f42ba779c56
7
- data.tar.gz: fd10fbc76409d2b1738b2e5abdd75ba68e6a34592ae6b7ed56f2fcac0f83079eba33b524704de4c29ff168040147e89d82fc0466746049c84b4f1df87bafaaeb
6
+ metadata.gz: df06bf35cd4e145679e0cf40b48d6823e8caa6b72954e1cdf3383797d6925045010ac993aceca7ef29affac6a1b46468ef2c444be6da0a3a60ddae0df2b56b72
7
+ data.tar.gz: dfdf0f1603bffe9be19f803d18a6e31d83ba9ac0bcf5bdbf566760f29afec09945da2c86f33b4f676afa7ac5b0c6cf9ea63492f3a4146361c6dc32b7fa9de161
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1 @@
1
- ''4��me�"[o>O��d��ˆV::�*�@�\�B��lb�%�q
2
- �i�ǻ���4���2Xx��"S6�A|�PU��5Y�{�;�]� [������Q�ա߲ ~�Ǟ"�4k1�E�F��FK
1
+ ��Х��N�E��t��b/+���3�6���ȇ�W�Z�%�� ʐ�2//zF� � $K��򏍽ɏ2n��s�fӃ�?@��a�I�`��&� ve$�_�f)L4�"�h ������n�D��~��̗�fd;���(y��KK�� �����K��y�8W�40�7��0���=�#�;j�`V� �c����5��k�nO=:o0Jb��O(����M���~H���FU.,�X�Ś�if���fϱg!P�`
@@ -1,13 +1,12 @@
1
1
  require 'json'
2
2
 
3
3
  module HALPresenter
4
- module ClassMethods
5
- def from_hal(presenter, payload, resource = nil)
6
- presenter.from_hal(payload, resource)
7
- end
8
- end
9
-
10
4
  module Deserializer
5
+ module ClassMethods
6
+ def from_hal(presenter, payload, resource = nil)
7
+ presenter.from_hal(payload, resource)
8
+ end
9
+ end
11
10
 
12
11
  class Error < StandardError; end
13
12
 
@@ -2,21 +2,20 @@ require 'hal_presenter/property'
2
2
  require 'hal_presenter/super_init'
3
3
 
4
4
  module HALPresenter
5
+ module Links
6
+ include SuperInit
5
7
 
6
- module ClassMethods
7
- def base_href=(base)
8
- @base_href = base&.sub(%r(/*$), '')
9
- end
8
+ module ClassMethods
9
+ def base_href=(base)
10
+ @base_href = base&.sub(%r(/*$), '')
11
+ end
10
12
 
11
- def href(href)
12
- return href if (@base_href ||= '').empty?
13
- return href if href =~ %r(\A(\w+://)?[^/])
14
- @base_href + href
13
+ def href(href)
14
+ return href if (@base_href ||= '').empty?
15
+ return href if href =~ %r(\A(\w+://)?[^/])
16
+ @base_href + href
17
+ end
15
18
  end
16
- end
17
-
18
- module Links
19
- include SuperInit
20
19
 
21
20
  class Link < HALPresenter::Property
22
21
  attr_reader :type, :deprecation, :profile, :title
@@ -29,6 +28,7 @@ module HALPresenter
29
28
  @deprecation = kwargs[:deprecation].freeze
30
29
  @profile = kwargs[:profile].freeze
31
30
  @title = kwargs[:title].freeze
31
+ @templated = kwargs[:templated].freeze
32
32
 
33
33
  curie = kwargs[:curie].to_s
34
34
  rel = [curie, rel.to_s].join(':') unless curie.empty?
@@ -46,13 +46,16 @@ module HALPresenter
46
46
  href = value(resource, options)
47
47
  return {} unless href
48
48
 
49
- {href: HALPresenter.href(href)}.tap do |hash|
50
- hash[:type] = type if type
51
- hash[:deprecation] = deprecation if deprecation
52
- hash[:profile] = profile if profile
53
- hash[:title] = title if title
54
- hash[:templated] = templated if templated
55
- end
49
+ values = href.respond_to?(:to_h) ? href.to_h : {}
50
+ values[:href] = HALPresenter.href(values[:href] || href)
51
+
52
+ {
53
+ type: type,
54
+ deprecation: deprecation,
55
+ profile: profile,
56
+ title: title,
57
+ templated: templated
58
+ }.compact.merge(values)
56
59
  end
57
60
  end
58
61
 
@@ -1,36 +1,36 @@
1
1
  module HALPresenter
2
2
  @presenters = {}
3
3
 
4
- module ClassMethods
5
- def register(model:, presenter:)
6
- return unless presenter && model
7
- @presenters[presenter] = model
8
- end
4
+ module Model
5
+ module ClassMethods
6
+ def register(model:, presenter:)
7
+ return unless presenter && model
8
+ @presenters[presenter] = model
9
+ end
9
10
 
10
- def unregister(presenter)
11
- @presenters.delete_if { |d,_| d == presenter }
12
- end
11
+ def unregister(presenter)
12
+ @presenters.delete_if { |d,_| d == presenter }
13
+ end
13
14
 
14
- def lookup_model(presenter)
15
- @presenters[presenter]
16
- end
15
+ def lookup_model(presenter)
16
+ @presenters[presenter]
17
+ end
17
18
 
18
- def lookup_presenter(model)
19
- presenters = lookup_presenters(model)
20
- return presenters.last unless presenters.empty?
21
- lookup_presenters(model.first).last if model.respond_to? :first
22
- end
19
+ def lookup_presenter(model)
20
+ presenters = lookup_presenters(model)
21
+ return presenters.last unless presenters.empty?
22
+ lookup_presenters(model.first).last if model.respond_to? :first
23
+ end
23
24
 
24
- def lookup_presenters(model)
25
- clazz = model.is_a?(Class) ? model : model.class
26
- presenters = @presenters.select { |_d, m| m == clazz }.keys
27
- return presenters unless presenters.empty?
28
- return [] unless clazz < BasicObject
29
- lookup_presenters(clazz.superclass)
25
+ def lookup_presenters(model)
26
+ clazz = model.is_a?(Class) ? model : model.class
27
+ presenters = @presenters.select { |_d, m| m == clazz }.keys
28
+ return presenters unless presenters.empty?
29
+ return [] unless clazz < BasicObject
30
+ lookup_presenters(clazz.superclass)
31
+ end
30
32
  end
31
- end
32
33
 
33
- module Model
34
34
  def self.included(base)
35
35
  base.extend ClassMethods
36
36
  end
@@ -1,12 +1,9 @@
1
1
  module HALPresenter
2
- module ClassMethods
2
+ class << self
3
3
  attr_accessor :paginate
4
4
  end
5
5
 
6
6
  class Pagination
7
- def self.included(base)
8
- base.extend ClassMethods
9
- end
10
7
 
11
8
  class Uri
12
9
  def self.parse(str)
@@ -3,31 +3,29 @@ require 'hal_presenter/pagination'
3
3
  require 'hal_presenter/curie_collection'
4
4
 
5
5
  module HALPresenter
6
+ module Serializer
7
+ module ClassMethods
8
+ def to_hal(resource, **options)
9
+ options = options.dup
10
+ presenter!(resource, **options).to_hal(resource, **options)
11
+ end
6
12
 
7
- module ClassMethods
8
- def to_hal(resource, **options)
9
- options = options.dup
10
- presenter!(resource, options).to_hal(resource, options)
11
- end
12
-
13
- def to_collection(resources, **options)
14
- options = options.dup
15
- presenter!(resources, options).to_collection(resources, options)
16
- end
13
+ def to_collection(resources, **options)
14
+ options = options.dup
15
+ presenter!(resources, **options).to_collection(resources, **options)
16
+ end
17
17
 
18
- private
18
+ private
19
19
 
20
- def presenter!(resources, **options)
21
- raise Serializer::Error, "resources is nil" if resources.nil?
22
- presenter = options.delete(:presenter)
23
- presenter ||= HALPresenter.lookup_presenter(resources)
24
- raise Serializer::Error, "No presenter for #{resources.first.class}" unless presenter
20
+ def presenter!(resources, **options)
21
+ raise Serializer::Error, "resources is nil" if resources.nil?
22
+ presenter = options.delete(:presenter)
23
+ presenter ||= HALPresenter.lookup_presenter(resources)
24
+ raise Serializer::Error, "No presenter for #{resources.first.class}" unless presenter
25
25
 
26
- presenter
26
+ presenter
27
+ end
27
28
  end
28
- end
29
-
30
- module Serializer
31
29
 
32
30
  class Error < StandardError; end
33
31
 
@@ -75,6 +73,7 @@ module HALPresenter
75
73
  end
76
74
 
77
75
  def to_collection_hash(resources, options)
76
+ resources ||= []
78
77
  policy = policy_for(nil, options)
79
78
  properties = collection_properties
80
79
  attributes = properties.attributes
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hal_presenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sammy Henningsson
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
13
  MIIDVjCCAj6gAwIBAgIBATANBgkqhkiG9w0BAQsFADAqMSgwJgYDVQQDDB9zYW1t
14
- eS5oZW5uaW5nc3Nvbi9EQz1oZXkvREM9Y29tMB4XDTIwMDgwNDE4MTAyOVoXDTIx
15
- MDgwNDE4MTAyOVowKjEoMCYGA1UEAwwfc2FtbXkuaGVubmluZ3Nzb24vREM9aGV5
14
+ eS5oZW5uaW5nc3Nvbi9EQz1oZXkvREM9Y29tMB4XDTIyMDEzMTIwNTQxMloXDTI0
15
+ MDEzMTIwNTQxMlowKjEoMCYGA1UEAwwfc2FtbXkuaGVubmluZ3Nzb24vREM9aGV5
16
16
  L0RDPWNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK+SDC1mfyhu
17
17
  cJ6Va21rIHUGscEtQrdvyBqxFG1s2TgPMAv4RbqwdJVPa7kjtbCzslADlUE1oru2
18
18
  C+rcJsMtVGX02ukMIPHT1OjTyy0/EMqLqSy3WeRI8APyDSxCVbe+h5BMf3zZnYfd
@@ -22,93 +22,93 @@ cert_chain:
22
22
  nIxTSJpPr2cCAwEAAaOBhjCBgzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNV
23
23
  HQ4EFgQUukjj1Cd2ea6IOHDLZe0ymzs2jWkwJAYDVR0RBB0wG4EZc2FtbXkuaGVu
24
24
  bmluZ3Nzb25AaGV5LmNvbTAkBgNVHRIEHTAbgRlzYW1teS5oZW5uaW5nc3NvbkBo
25
- ZXkuY29tMA0GCSqGSIb3DQEBCwUAA4IBAQAEtv48barHOksR+CEF+Nu5ZjzXksi0
26
- rI2JMmuDTlQBw0/m79+Om1cPzBKKR7ODGytjQ7NAj9VWQcw8Oc/K4z63JbD13G3Y
27
- 45/GTTCCae5YyO/g8BpkFeFwZTvJBwD1HQvMBjBi8WMk+Yr00EUoiLExuL0VSjJ9
28
- grmwk+vA+68PWAkYOAkNOonQ6nT3UgmbK9XGoINSxHwn1Njxyw0dXsuZeaznJzhy
29
- D4OCgJwXzne+Jeqc60ISM5a6/eFZGVyfI15X2fnxXXVrGu3EMnrgKuHxTNUfjaBL
30
- Xs+28o/7SxG1CNyMq1HAmDvUPP3bMyzXTtVr61Kd2uyS1StS5s9XFedR
25
+ ZXkuY29tMA0GCSqGSIb3DQEBCwUAA4IBAQCNUrjx1+L5W9R5O5MF3fnnNIyxOXGa
26
+ qzqpmXpTd7pHUGvSzVxYM/NIkUHSSPyxLAG+RYMPJHjDOSzhLmOUbgpfOsQ8sqUP
27
+ plABBC03e/+oDwFwlHefonil+sp/AOT9TYZJQbShjKt3/X+VGzjtujJZwvKgiiP0
28
+ Ht5Q4dvW1ZqUZgvXdYM1LnCX7I3WjoRyhOwdSlaEz5gnD+KYewHiiByK1Jv2n0PG
29
+ DVzXaUnsmwP+jQ1PkDa5q8ibBzMd2c6Hmm87UDqPxZtML0bF9SjrpbyLMjwtXaMA
30
+ WDPp0ajpdUZ9GPHsrVNYXiOfQIqcmlmpYVsH1o7vuneUIcIDMrnMDChh
31
31
  -----END CERTIFICATE-----
32
- date: 2020-08-04 00:00:00.000000000 Z
32
+ date: 2022-01-31 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rake
36
36
  requirement: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '10.0'
41
38
  - - "~>"
42
39
  - !ruby/object:Gem::Version
43
40
  version: '12.0'
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '10.0'
44
44
  type: :development
45
45
  prerelease: false
46
46
  version_requirements: !ruby/object:Gem::Requirement
47
47
  requirements:
48
- - - ">="
49
- - !ruby/object:Gem::Version
50
- version: '10.0'
51
48
  - - "~>"
52
49
  - !ruby/object:Gem::Version
53
50
  version: '12.0'
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: activesupport
56
56
  requirement: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: '4.0'
61
58
  - - "~>"
62
59
  - !ruby/object:Gem::Version
63
60
  version: '5.0'
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '4.0'
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- version: '4.0'
71
68
  - - "~>"
72
69
  - !ruby/object:Gem::Version
73
70
  version: '5.0'
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '4.0'
74
74
  - !ruby/object:Gem::Dependency
75
75
  name: minitest
76
76
  requirement: !ruby/object:Gem::Requirement
77
77
  requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- version: '5.0'
81
78
  - - "~>"
82
79
  - !ruby/object:Gem::Version
83
80
  version: '5.10'
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '5.0'
84
84
  type: :development
85
85
  prerelease: false
86
86
  version_requirements: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- version: '5.0'
91
88
  - - "~>"
92
89
  - !ruby/object:Gem::Version
93
90
  version: '5.10'
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '5.0'
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: byebug
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  requirements:
98
- - - ">="
98
+ - - "~>"
99
99
  - !ruby/object:Gem::Version
100
100
  version: '9.0'
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '9.0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '9.0'
111
- - - "~>"
111
+ - - ">="
112
112
  - !ruby/object:Gem::Version
113
113
  version: '9.0'
114
114
  - !ruby/object:Gem::Dependency
@@ -183,7 +183,7 @@ homepage: https://github.com/sammyhenningsson/hal_presenter
183
183
  licenses:
184
184
  - MIT
185
185
  metadata: {}
186
- post_install_message:
186
+ post_install_message:
187
187
  rdoc_options: []
188
188
  require_paths:
189
189
  - lib
@@ -198,8 +198,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
198
  - !ruby/object:Gem::Version
199
199
  version: '0'
200
200
  requirements: []
201
- rubygems_version: 3.0.3
202
- signing_key:
201
+ rubygems_version: 3.1.6
202
+ signing_key:
203
203
  specification_version: 4
204
204
  summary: JSON HAL serializer
205
205
  test_files: []
metadata.gz.sig CHANGED
Binary file