grape-hypertext_application_language 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/grape-hypertext_application_language.gemspec +1 -1
- data/lib/grape/formatter/hal/json.rb +25 -2
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffe1cef37af0bb17749a6a6a1a07e522560f61ce
|
4
|
+
data.tar.gz: 2673e37724c016727d7bb999c69df7e9c486060e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ea3bc42966802ff300ce2ec91ca2d00125b66e2c12fcd697a5aa213a0f16aa666ca2fb16741ed75c98481d18a3fe41f20c8df333022824e56b8797a363b0384
|
7
|
+
data.tar.gz: 31c11910e5f8c6cecafff58591602e7d1894eb7d6eac1fa42f132f13525b7dd77ffd58740c0bb93342e8a63e6d3fa61fc0e5d970ffb37a848392cb44dad8456c
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
grape-hypertext_application_language (0.
|
4
|
+
grape-hypertext_application_language (0.1.0)
|
5
5
|
addressable
|
6
6
|
grape
|
7
7
|
hypertext_application_language
|
@@ -9,7 +9,7 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (4.2.
|
12
|
+
activesupport (4.2.5)
|
13
13
|
i18n (~> 0.7)
|
14
14
|
json (~> 1.7, >= 1.7.7)
|
15
15
|
minitest (~> 5.1)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = 'grape-hypertext_application_language'
|
3
|
-
spec.version = '0.
|
3
|
+
spec.version = '0.1.0'
|
4
4
|
spec.summary = %q{Grape extensions for Hypertext Application Language}
|
5
5
|
spec.description = %q{}
|
6
6
|
spec.homepage = 'http://stateless.co/hal_specification.html'
|
@@ -22,10 +22,33 @@ module Grape::Formatter::Hal
|
|
22
22
|
# representation. Passes the Rack environment to the HAL
|
23
23
|
# converter. Converters can use the environment to extract addressing
|
24
24
|
# information for the representation's links, including the self link.
|
25
|
+
#
|
26
|
+
# Handles arrays of objects if, and only if, the elements themselves respond
|
27
|
+
# to +to_hal+. In such cases, it replaces the array body with a HAL
|
28
|
+
# representation conforming to a HAL collection where the collection
|
29
|
+
# representation includes links to the elements in the collection as well as
|
30
|
+
# embedding the nested resources. Uses the request path for the self link;
|
31
|
+
# and uses the path, less its leading slash, as the relation.
|
25
32
|
def self.call(body, env)
|
26
33
|
unless body.is_a?(HypertextApplicationLanguage::Representation)
|
27
|
-
|
28
|
-
|
34
|
+
if body.respond_to?(:first) && body.first.respond_to?(:to_hal)
|
35
|
+
representation = HypertextApplicationLanguage::Representation.new
|
36
|
+
|
37
|
+
rel = env['PATH_INFO'][1..-1]
|
38
|
+
href = env['REQUEST_PATH']
|
39
|
+
representation.with_link(HypertextApplicationLanguage::Link::SELF_REL, href)
|
40
|
+
|
41
|
+
body.each do |resource|
|
42
|
+
resource_representation = resource.to_hal(env: env)
|
43
|
+
representation.with_link(rel, resource_representation.link.href)
|
44
|
+
representation.with_representation(rel, resource_representation)
|
45
|
+
end
|
46
|
+
|
47
|
+
body = representation
|
48
|
+
else
|
49
|
+
return body unless body.respond_to?(:to_hal)
|
50
|
+
body = body.to_hal(env: env)
|
51
|
+
end
|
29
52
|
end
|
30
53
|
|
31
54
|
endpoint = env['api.endpoint']
|
metadata
CHANGED
@@ -1,80 +1,80 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-hypertext_application_language
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roy Ratcliffe
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
+
name: grape
|
14
15
|
requirement: !ruby/object:Gem::Requirement
|
15
16
|
requirements:
|
16
17
|
- - ">="
|
17
18
|
- !ruby/object:Gem::Version
|
18
19
|
version: '0'
|
19
|
-
name: grape
|
20
|
-
prerelease: false
|
21
20
|
type: :runtime
|
21
|
+
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
+
name: hypertext_application_language
|
28
29
|
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
31
|
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
|
-
name: hypertext_application_language
|
34
|
-
prerelease: false
|
35
34
|
type: :runtime
|
35
|
+
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
+
name: addressable
|
42
43
|
requirement: !ruby/object:Gem::Requirement
|
43
44
|
requirements:
|
44
45
|
- - ">="
|
45
46
|
- !ruby/object:Gem::Version
|
46
47
|
version: '0'
|
47
|
-
name: addressable
|
48
|
-
prerelease: false
|
49
48
|
type: :runtime
|
49
|
+
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
56
57
|
requirement: !ruby/object:Gem::Requirement
|
57
58
|
requirements:
|
58
59
|
- - ">="
|
59
60
|
- !ruby/object:Gem::Version
|
60
61
|
version: '0'
|
61
|
-
name: bundler
|
62
|
-
prerelease: false
|
63
62
|
type: :development
|
63
|
+
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
70
71
|
requirement: !ruby/object:Gem::Requirement
|
71
72
|
requirements:
|
72
73
|
- - ">="
|
73
74
|
- !ruby/object:Gem::Version
|
74
75
|
version: '0'
|
75
|
-
name: rake
|
76
|
-
prerelease: false
|
77
76
|
type: :development
|
77
|
+
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
@@ -100,7 +100,7 @@ homepage: http://stateless.co/hal_specification.html
|
|
100
100
|
licenses:
|
101
101
|
- MIT
|
102
102
|
metadata: {}
|
103
|
-
post_install_message:
|
103
|
+
post_install_message:
|
104
104
|
rdoc_options: []
|
105
105
|
require_paths:
|
106
106
|
- lib
|
@@ -115,9 +115,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '0'
|
117
117
|
requirements: []
|
118
|
-
rubyforge_project:
|
118
|
+
rubyforge_project:
|
119
119
|
rubygems_version: 2.4.8
|
120
|
-
signing_key:
|
120
|
+
signing_key:
|
121
121
|
specification_version: 4
|
122
122
|
summary: Grape extensions for Hypertext Application Language
|
123
123
|
test_files: []
|