hal_api-rails 1.1.5 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.ruby-version +1 -1
- data/Gemfile +2 -0
- data/Rakefile +8 -5
- data/bin/console +4 -3
- data/hal_api-rails.gemspec +23 -24
- data/lib/hal_api/controller/actions.rb +2 -4
- data/lib/hal_api/controller/exceptions.rb +19 -14
- data/lib/hal_api/paged_collection.rb +3 -2
- data/lib/hal_api/rails/version.rb +3 -1
- data/lib/hal_api/representer/collection_paging.rb +4 -4
- data/lib/hal_api/representer/link_serialize.rb +2 -1
- data/lib/hal_api/representer/uri_methods.rb +5 -4
- metadata +37 -66
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e7c08d700a00bfc1ccec03c2cbd3c92d3094ad48d70eca4eba39dce8d9cb78fa
|
4
|
+
data.tar.gz: 3a44c0e260cb3b50cd6e6dbabd2806a655d19a015b5029f50a8f7dc5db2b5ba5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebf622a8c79f64b987a20f30122b07277a905dc7964fd42e11e72ca45e638d653fa39d4ac06618a4037247d86579d94e30f41f30c0953d93804c17049cd827c4
|
7
|
+
data.tar.gz: aacadd75279e2c4841ef3cf3c912fddbce1d9ae8110595541dbb07a470b5e7d639a1c51f91ddbfc256364608935ffe49842905c470ca349edd9b1aaf9d904263
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.7.2
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/testtask'
|
3
5
|
|
4
6
|
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs <<
|
6
|
-
t.libs <<
|
7
|
+
t.libs << 'test'
|
8
|
+
t.libs << 'lib'
|
7
9
|
t.test_files = FileList['test/**/*_test.rb']
|
10
|
+
t.warning = false
|
8
11
|
end
|
9
12
|
|
10
|
-
task :
|
13
|
+
task default: :test
|
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'hal_api/rails'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "hal_api/rails"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start
|
data/hal_api-rails.gemspec
CHANGED
@@ -1,36 +1,35 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'hal_api/rails/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
+
spec.name = 'hal_api-rails'
|
8
9
|
spec.version = HalApi::Rails::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
10
|
+
spec.authors = ['Chris Rhoden', 'Andrew Kuklewicz']
|
11
|
+
spec.email = ['carhoden@gmail.com', 'andrew@beginsinwonder.com']
|
11
12
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
13
|
+
spec.summary = 'JSON HAL APIs on Rails in the style of PRX'
|
14
|
+
spec.description = 'JSON HAL APIs on Rails in the style of PRX v4. Uses ROAR'
|
15
|
+
spec.homepage = 'https://www.github.com/PRX/'
|
16
|
+
spec.license = 'MIT'
|
16
17
|
|
17
18
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir =
|
19
|
+
spec.bindir = 'exe'
|
19
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
21
|
+
spec.require_paths = ['lib']
|
21
22
|
|
22
|
-
spec.add_dependency
|
23
|
-
spec.add_dependency
|
24
|
-
spec.add_dependency
|
25
|
-
spec.add_dependency
|
26
|
-
spec.add_dependency "responders", "~> 3.0"
|
27
|
-
spec.add_dependency "roar-rails", "~> 1.1.0"
|
28
|
-
spec.add_dependency "multi_json"
|
23
|
+
spec.add_dependency 'activemodel'
|
24
|
+
spec.add_dependency 'activesupport'
|
25
|
+
spec.add_dependency 'multi_json'
|
26
|
+
spec.add_dependency 'roar-rails'
|
29
27
|
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
35
|
-
spec.add_development_dependency
|
28
|
+
spec.add_development_dependency 'bundler'
|
29
|
+
spec.add_development_dependency 'kaminari'
|
30
|
+
spec.add_development_dependency 'minitest'
|
31
|
+
spec.add_development_dependency 'pry-byebug'
|
32
|
+
spec.add_development_dependency 'rack-test'
|
33
|
+
spec.add_development_dependency 'rails', '~> 5.2.4'
|
34
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
36
35
|
end
|
@@ -74,8 +74,7 @@ module HalApi::Controller::Actions
|
|
74
74
|
if zoom_param
|
75
75
|
p[:user_options] = (p[:user_options] || {}).merge(zoom: zoom_param)
|
76
76
|
end
|
77
|
-
end.
|
78
|
-
to_h
|
77
|
+
end.to_h
|
79
78
|
end
|
80
79
|
|
81
80
|
def zoom_param
|
@@ -91,7 +90,7 @@ module HalApi::Controller::Actions
|
|
91
90
|
end
|
92
91
|
|
93
92
|
def hal_authorize(resource)
|
94
|
-
|
93
|
+
unless respond_to?(:authorize, true)
|
95
94
|
define_singleton_method(:authorize) do |_resource|
|
96
95
|
true
|
97
96
|
end
|
@@ -101,7 +100,6 @@ module HalApi::Controller::Actions
|
|
101
100
|
authorize(resource)
|
102
101
|
end
|
103
102
|
|
104
|
-
|
105
103
|
module ClassMethods
|
106
104
|
def allow_params(action, *params)
|
107
105
|
self.valid_params ||= {}
|
@@ -7,22 +7,27 @@ module HalApi::Controller::Exceptions
|
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
|
9
9
|
def respond_with_error(exception)
|
10
|
-
wrapper =
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
log_error(request.env, wrapper)
|
17
|
-
|
18
|
-
error = exception
|
19
|
-
if !error.is_a?(HalApi::Errors::ApiError)
|
20
|
-
error = HalApi::Errors::ApiError.new(error.message).tap do |e|
|
21
|
-
e.set_backtrace(error.backtrace)
|
10
|
+
wrapper =
|
11
|
+
if HalApi.rails_major_version >= 5
|
12
|
+
::ActionDispatch::ExceptionWrapper.new(ActiveSupport::BacktraceCleaner.new, exception)
|
13
|
+
else
|
14
|
+
::ActionDispatch::ExceptionWrapper.new(request.env, exception)
|
22
15
|
end
|
23
|
-
end
|
24
16
|
|
25
|
-
|
17
|
+
error =
|
18
|
+
if exception.is_a?(HalApi::Errors::ApiError) && exception.status >= 500
|
19
|
+
log_error(request.env, wrapper)
|
20
|
+
notice_error(exception)
|
21
|
+
exception
|
22
|
+
elsif exception.is_a?(HalApi::Errors::ApiError)
|
23
|
+
exception
|
24
|
+
else
|
25
|
+
log_error(request.env, wrapper)
|
26
|
+
notice_error(exception)
|
27
|
+
HalApi::Errors::ApiError.new(exception.message).tap do |e|
|
28
|
+
e.set_backtrace(exception.backtrace)
|
29
|
+
end
|
30
|
+
end
|
26
31
|
|
27
32
|
respond_with(
|
28
33
|
error,
|
@@ -72,9 +72,10 @@ class HalApi::PagedCollection
|
|
72
72
|
# If this is an embedded collection, the parent will be set here for use in urls
|
73
73
|
def parent
|
74
74
|
rep = options[:parent]
|
75
|
-
return rep unless rep.respond_to?(:becomes)
|
75
|
+
return rep unless rep.respond_to?(:becomes, true)
|
76
|
+
|
76
77
|
klass = rep.class.try(:base_class)
|
77
|
-
|
78
|
+
klass && (klass != rep.class) ? rep.becomes(klass) : rep
|
78
79
|
end
|
79
80
|
|
80
81
|
def count
|
@@ -64,10 +64,10 @@ module HalApi::Representer::CollectionPaging
|
|
64
64
|
return result
|
65
65
|
end
|
66
66
|
|
67
|
-
if represented_url.respond_to?(:call)
|
68
|
-
|
69
|
-
elsif
|
70
|
-
|
67
|
+
if represented_url.respond_to?(:call, true)
|
68
|
+
instance_exec(options, &represented_url)
|
69
|
+
elsif respond_to?(represented_url, true)
|
70
|
+
send(represented_url, options)
|
71
71
|
else
|
72
72
|
represented_url.to_s
|
73
73
|
end
|
@@ -15,7 +15,8 @@ module HalApi::Representer::LinkSerialize
|
|
15
15
|
if options.is_a?(Hash) && (options.delete(:writeable) || options[:reader])
|
16
16
|
name = options[:rel].to_s.split(':').last.split('/').last
|
17
17
|
pname = "set_#{name}_uri"
|
18
|
-
reader = options.delete(:reader) || ->(
|
18
|
+
reader = options.delete(:reader) || ->(obj) do
|
19
|
+
doc = obj[:doc]
|
19
20
|
try("#{name}_id=", id_from_url(doc[pname])) if doc[pname]
|
20
21
|
Representable::Pipeline::Stop
|
21
22
|
end
|
@@ -68,9 +68,10 @@ module HalApi::Representer::UriMethods
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def becomes_represented_class(rep)
|
71
|
-
return rep unless rep.respond_to?(:becomes)
|
71
|
+
return rep unless rep.respond_to?(:becomes, true)
|
72
|
+
|
72
73
|
klass = rep.try(:item_class) || rep.class.try(:base_class)
|
73
|
-
|
74
|
+
klass && (klass != rep.class) ? rep.becomes(klass) : rep
|
74
75
|
end
|
75
76
|
|
76
77
|
def alternate_url(*path)
|
@@ -103,9 +104,9 @@ module HalApi::Representer::UriMethods
|
|
103
104
|
part.to_s.dasherize
|
104
105
|
else
|
105
106
|
klass = part.is_a?(Class) ? part : (part.try(:item_class) || part.class)
|
106
|
-
if klass.respond_to?(:base_class) && !klass.superclass.name.demodulize.starts_with?('Base')
|
107
|
+
if klass.respond_to?(:base_class, true) && !klass.superclass.name.demodulize.starts_with?('Base')
|
107
108
|
parent = klass.superclass.name.underscore.dasherize
|
108
|
-
child = klass.name.underscore.gsub(/_#{parent}$/,
|
109
|
+
child = klass.name.underscore.gsub(/_#{parent}$/, '').dasherize
|
109
110
|
[parent, child]
|
110
111
|
else
|
111
112
|
klass.name.underscore.dasherize
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hal_api-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Rhoden
|
8
8
|
- Andrew Kuklewicz
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-07-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -17,30 +17,30 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: '0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: '0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
29
|
+
name: activesupport
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: '0'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: '0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
|
-
name:
|
43
|
+
name: multi_json
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - ">="
|
@@ -54,55 +54,27 @@ dependencies:
|
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
|
-
name:
|
57
|
+
name: roar-rails
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
62
|
+
version: '0'
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: responders
|
72
|
-
requirement: !ruby/object:Gem::Requirement
|
73
|
-
requirements:
|
74
|
-
- - "~>"
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: '3.0'
|
77
|
-
type: :runtime
|
78
|
-
prerelease: false
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
80
|
-
requirements:
|
81
|
-
- - "~>"
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: '3.0'
|
84
|
-
- !ruby/object:Gem::Dependency
|
85
|
-
name: roar-rails
|
86
|
-
requirement: !ruby/object:Gem::Requirement
|
87
|
-
requirements:
|
88
|
-
- - "~>"
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version: 1.1.0
|
91
|
-
type: :runtime
|
92
|
-
prerelease: false
|
93
|
-
version_requirements: !ruby/object:Gem::Requirement
|
94
|
-
requirements:
|
95
|
-
- - "~>"
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: 1.1.0
|
69
|
+
version: '0'
|
98
70
|
- !ruby/object:Gem::Dependency
|
99
|
-
name:
|
71
|
+
name: bundler
|
100
72
|
requirement: !ruby/object:Gem::Requirement
|
101
73
|
requirements:
|
102
74
|
- - ">="
|
103
75
|
- !ruby/object:Gem::Version
|
104
76
|
version: '0'
|
105
|
-
type: :
|
77
|
+
type: :development
|
106
78
|
prerelease: false
|
107
79
|
version_requirements: !ruby/object:Gem::Requirement
|
108
80
|
requirements:
|
@@ -110,7 +82,7 @@ dependencies:
|
|
110
82
|
- !ruby/object:Gem::Version
|
111
83
|
version: '0'
|
112
84
|
- !ruby/object:Gem::Dependency
|
113
|
-
name:
|
85
|
+
name: kaminari
|
114
86
|
requirement: !ruby/object:Gem::Requirement
|
115
87
|
requirements:
|
116
88
|
- - ">="
|
@@ -124,35 +96,35 @@ dependencies:
|
|
124
96
|
- !ruby/object:Gem::Version
|
125
97
|
version: '0'
|
126
98
|
- !ruby/object:Gem::Dependency
|
127
|
-
name:
|
99
|
+
name: minitest
|
128
100
|
requirement: !ruby/object:Gem::Requirement
|
129
101
|
requirements:
|
130
|
-
- - "
|
102
|
+
- - ">="
|
131
103
|
- !ruby/object:Gem::Version
|
132
|
-
version: '
|
104
|
+
version: '0'
|
133
105
|
type: :development
|
134
106
|
prerelease: false
|
135
107
|
version_requirements: !ruby/object:Gem::Requirement
|
136
108
|
requirements:
|
137
|
-
- - "
|
109
|
+
- - ">="
|
138
110
|
- !ruby/object:Gem::Version
|
139
|
-
version: '
|
111
|
+
version: '0'
|
140
112
|
- !ruby/object:Gem::Dependency
|
141
|
-
name:
|
113
|
+
name: pry-byebug
|
142
114
|
requirement: !ruby/object:Gem::Requirement
|
143
115
|
requirements:
|
144
|
-
- - "
|
116
|
+
- - ">="
|
145
117
|
- !ruby/object:Gem::Version
|
146
|
-
version:
|
118
|
+
version: '0'
|
147
119
|
type: :development
|
148
120
|
prerelease: false
|
149
121
|
version_requirements: !ruby/object:Gem::Requirement
|
150
122
|
requirements:
|
151
|
-
- - "
|
123
|
+
- - ">="
|
152
124
|
- !ruby/object:Gem::Version
|
153
|
-
version:
|
125
|
+
version: '0'
|
154
126
|
- !ruby/object:Gem::Dependency
|
155
|
-
name:
|
127
|
+
name: rack-test
|
156
128
|
requirement: !ruby/object:Gem::Requirement
|
157
129
|
requirements:
|
158
130
|
- - ">="
|
@@ -166,33 +138,33 @@ dependencies:
|
|
166
138
|
- !ruby/object:Gem::Version
|
167
139
|
version: '0'
|
168
140
|
- !ruby/object:Gem::Dependency
|
169
|
-
name:
|
141
|
+
name: rails
|
170
142
|
requirement: !ruby/object:Gem::Requirement
|
171
143
|
requirements:
|
172
|
-
- - "
|
144
|
+
- - "~>"
|
173
145
|
- !ruby/object:Gem::Version
|
174
|
-
version:
|
146
|
+
version: 5.2.4
|
175
147
|
type: :development
|
176
148
|
prerelease: false
|
177
149
|
version_requirements: !ruby/object:Gem::Requirement
|
178
150
|
requirements:
|
179
|
-
- - "
|
151
|
+
- - "~>"
|
180
152
|
- !ruby/object:Gem::Version
|
181
|
-
version:
|
153
|
+
version: 5.2.4
|
182
154
|
- !ruby/object:Gem::Dependency
|
183
|
-
name:
|
155
|
+
name: rake
|
184
156
|
requirement: !ruby/object:Gem::Requirement
|
185
157
|
requirements:
|
186
158
|
- - ">="
|
187
159
|
- !ruby/object:Gem::Version
|
188
|
-
version:
|
160
|
+
version: 12.3.3
|
189
161
|
type: :development
|
190
162
|
prerelease: false
|
191
163
|
version_requirements: !ruby/object:Gem::Requirement
|
192
164
|
requirements:
|
193
165
|
- - ">="
|
194
166
|
- !ruby/object:Gem::Version
|
195
|
-
version:
|
167
|
+
version: 12.3.3
|
196
168
|
description: JSON HAL APIs on Rails in the style of PRX v4. Uses ROAR
|
197
169
|
email:
|
198
170
|
- carhoden@gmail.com
|
@@ -240,7 +212,7 @@ homepage: https://www.github.com/PRX/
|
|
240
212
|
licenses:
|
241
213
|
- MIT
|
242
214
|
metadata: {}
|
243
|
-
post_install_message:
|
215
|
+
post_install_message:
|
244
216
|
rdoc_options: []
|
245
217
|
require_paths:
|
246
218
|
- lib
|
@@ -255,9 +227,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
255
227
|
- !ruby/object:Gem::Version
|
256
228
|
version: '0'
|
257
229
|
requirements: []
|
258
|
-
|
259
|
-
|
260
|
-
signing_key:
|
230
|
+
rubygems_version: 3.1.6
|
231
|
+
signing_key:
|
261
232
|
specification_version: 4
|
262
233
|
summary: JSON HAL APIs on Rails in the style of PRX
|
263
234
|
test_files: []
|