hal_api-rails 0.7.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +1 -1
- data/hal_api-rails.gemspec +3 -3
- data/lib/hal_api/controller/exceptions.rb +7 -8
- data/lib/hal_api/errors.rb +0 -8
- data/lib/hal_api/rails/version.rb +1 -1
- data/lib/hal_api/representer/embeds.rb +23 -8
- data/lib/hal_api/representer/link_serialize.rb +2 -1
- metadata +9 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 35f7ab8e051a6d7132ecf26800670c4e56489c7371539ac92fdcc6e88fb5d280
|
4
|
+
data.tar.gz: 5fd5ecbdd0ba0287c0c01e1e5ed24cd23b5cb10aa157be28224b7ec6c6c25698
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 653ca1b7461fd1c3b598904e85e430c4632485f6c390192deaab63dc8e0a13c3970ed4d94486d1cf749d09966edf4055602b00a71e3f54c7b83a08bdc21a57b2
|
7
|
+
data.tar.gz: 11ce89bb941bf1e9f83d377fe1bc7b0da9a6e94cd7d7e93fb8b516348ceb7550e37966c2cbb6b4357f90bed927130a5a44658de12572ac0a37e1a2f270890f05
|
data/.travis.yml
CHANGED
data/hal_api-rails.gemspec
CHANGED
@@ -23,13 +23,13 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency "actionpack", ">= 3.0.0"
|
24
24
|
spec.add_dependency "rack-test"
|
25
25
|
spec.add_dependency "activesupport", ">= 3.0.0"
|
26
|
-
spec.add_dependency "responders", "~>
|
27
|
-
spec.add_dependency "roar-rails", "~> 1.0
|
26
|
+
spec.add_dependency "responders", "~> 3.0"
|
27
|
+
spec.add_dependency "roar-rails", "~> 1.1.0"
|
28
28
|
spec.add_dependency "multi_json"
|
29
29
|
|
30
30
|
spec.add_development_dependency "bundler"
|
31
31
|
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
-
spec.add_development_dependency "rails", "~>
|
32
|
+
spec.add_development_dependency "rails", "~> 5.2.4"
|
33
33
|
spec.add_development_dependency "pry-byebug"
|
34
34
|
spec.add_development_dependency "minitest"
|
35
35
|
spec.add_development_dependency "kaminari"
|
@@ -11,10 +11,10 @@ module HalApi::Controller::Exceptions
|
|
11
11
|
when 5
|
12
12
|
::ActionDispatch::ExceptionWrapper.new(ActiveSupport::BacktraceCleaner.new, exception)
|
13
13
|
else
|
14
|
-
::ActionDispatch::ExceptionWrapper.new(env, exception)
|
14
|
+
::ActionDispatch::ExceptionWrapper.new(request.env, exception)
|
15
15
|
end
|
16
16
|
|
17
|
-
log_error(env, wrapper)
|
17
|
+
log_error(request.env, wrapper)
|
18
18
|
|
19
19
|
error = exception
|
20
20
|
if !error.is_a?(HalApi::Errors::ApiError)
|
@@ -25,12 +25,11 @@ module HalApi::Controller::Exceptions
|
|
25
25
|
|
26
26
|
notice_error(exception) if error.status >= 500
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
)
|
28
|
+
json = {status: error.status, message: error.message}
|
29
|
+
if Rails.configuration.try(:consider_all_requests_local)
|
30
|
+
json[:backtrace] = error.backtrace
|
31
|
+
end
|
32
|
+
render status: error.status, json: json
|
34
33
|
end
|
35
34
|
|
36
35
|
def log_error(env, wrapper)
|
data/lib/hal_api/errors.rb
CHANGED
@@ -48,12 +48,4 @@ module HalApi::Errors
|
|
48
48
|
super(msg, 400, hint)
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
52
|
-
module Representer
|
53
|
-
include Roar::JSON::HAL
|
54
|
-
|
55
|
-
property :status
|
56
|
-
property :message
|
57
|
-
property :backtrace, if: -> (*) { Rails.configuration.try(:consider_all_requests_local) }
|
58
|
-
end
|
59
51
|
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'active_support/concern'
|
2
2
|
require 'hal_api/paged_collection'
|
3
|
+
require "representable/pipeline_factories"
|
3
4
|
|
4
5
|
# expects underlying model to have filename, class, and id attributes
|
5
6
|
module HalApi::Representer::Embeds
|
6
7
|
extend ActiveSupport::Concern
|
7
8
|
|
8
9
|
included do
|
9
|
-
Representable::
|
10
|
+
Representable::Binding.send(:include, HalApiRailsRenderPipeline) if !Representable::Binding.include?(HalApiRailsRenderPipeline)
|
10
11
|
end
|
11
12
|
|
12
13
|
def normalize_options!(options)
|
@@ -18,22 +19,36 @@ module HalApi::Representer::Embeds
|
|
18
19
|
[propagated_options, private_options]
|
19
20
|
end
|
20
21
|
|
21
|
-
module
|
22
|
+
module HalApiRailsRenderPipeline
|
22
23
|
|
23
24
|
def skip_property?(binding, private_options)
|
24
25
|
super(binding, private_options) || suppress_embed?(binding, private_options)
|
25
26
|
end
|
26
27
|
|
28
|
+
def render_functions
|
29
|
+
funcs = super
|
30
|
+
f = ->(input, options) do
|
31
|
+
if suppress_embed?(input, options)
|
32
|
+
return Representable::Pipeline::Stop
|
33
|
+
end
|
34
|
+
end
|
35
|
+
[f] + funcs
|
36
|
+
end
|
37
|
+
|
27
38
|
# embed if zoomed
|
28
|
-
def suppress_embed?(
|
29
|
-
|
30
|
-
|
39
|
+
def suppress_embed?(input, options)
|
40
|
+
user_options = options[:options]
|
41
|
+
|
42
|
+
binding = options[:binding]
|
43
|
+
|
44
|
+
name = binding.evaluate_option(:as, input, options)
|
45
|
+
|
46
|
+
embedded = binding[:embedded]
|
31
47
|
|
32
|
-
# not embedded, return false - nothing to suppress
|
33
48
|
return false if !embedded
|
34
49
|
|
35
|
-
|
36
|
-
!embed_zoomed?(name, binding[:zoom],
|
50
|
+
## check if it should be zoomed, suppress if not
|
51
|
+
!embed_zoomed?(name, binding[:zoom], user_options[:zoom])
|
37
52
|
end
|
38
53
|
|
39
54
|
def embed_zoomed?(name, zoom_def = nil, zoom_param = nil)
|
@@ -15,8 +15,9 @@ 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) || ->(doc
|
18
|
+
reader = options.delete(:reader) || ->(represented:, doc:, **) do
|
19
19
|
try("#{name}_id=", id_from_url(doc[pname])) if doc[pname]
|
20
|
+
Representable::Pipeline::Stop
|
20
21
|
end
|
21
22
|
|
22
23
|
property(pname, readable: false, reader: reader)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hal_api-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Rhoden
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-01-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -73,28 +73,28 @@ dependencies:
|
|
73
73
|
requirements:
|
74
74
|
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: '
|
76
|
+
version: '3.0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
81
|
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version: '
|
83
|
+
version: '3.0'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: roar-rails
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
88
|
- - "~>"
|
89
89
|
- !ruby/object:Gem::Version
|
90
|
-
version: 1.0
|
90
|
+
version: 1.1.0
|
91
91
|
type: :runtime
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
95
|
- - "~>"
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version: 1.0
|
97
|
+
version: 1.1.0
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
99
|
name: multi_json
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -143,14 +143,14 @@ dependencies:
|
|
143
143
|
requirements:
|
144
144
|
- - "~>"
|
145
145
|
- !ruby/object:Gem::Version
|
146
|
-
version:
|
146
|
+
version: 5.2.4
|
147
147
|
type: :development
|
148
148
|
prerelease: false
|
149
149
|
version_requirements: !ruby/object:Gem::Requirement
|
150
150
|
requirements:
|
151
151
|
- - "~>"
|
152
152
|
- !ruby/object:Gem::Version
|
153
|
-
version:
|
153
|
+
version: 5.2.4
|
154
154
|
- !ruby/object:Gem::Dependency
|
155
155
|
name: pry-byebug
|
156
156
|
requirement: !ruby/object:Gem::Requirement
|
@@ -254,8 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
254
254
|
- !ruby/object:Gem::Version
|
255
255
|
version: '0'
|
256
256
|
requirements: []
|
257
|
-
|
258
|
-
rubygems_version: 2.5.2.3
|
257
|
+
rubygems_version: 3.0.3
|
259
258
|
signing_key:
|
260
259
|
specification_version: 4
|
261
260
|
summary: JSON HAL APIs on Rails in the style of PRX
|