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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e8ca09414db3082766a5b86ee83310563af05628
4
- data.tar.gz: 002aceca75878356759760d73f5dd68cd6dc03d4
2
+ SHA256:
3
+ metadata.gz: 35f7ab8e051a6d7132ecf26800670c4e56489c7371539ac92fdcc6e88fb5d280
4
+ data.tar.gz: 5fd5ecbdd0ba0287c0c01e1e5ed24cd23b5cb10aa157be28224b7ec6c6c25698
5
5
  SHA512:
6
- metadata.gz: 25f710db7f628fbbd0b708c06e04f4b1f2eb8335ecbb8a48311e68ac4259ad5cfe80d5bbbd02df41d55ea846c8b0d4423055cf1fcbe64f09e37217d1d7c92d33
7
- data.tar.gz: df4c7da616d62d01b5dddeb031b2e2c7bd94b61e6399452ab17fbe7a43ffe12c1909e5b138821de4e74dad83ac98295355a1550729a5a4220508f24faaa9f849
6
+ metadata.gz: 653ca1b7461fd1c3b598904e85e430c4632485f6c390192deaab63dc8e0a13c3970ed4d94486d1cf749d09966edf4055602b00a71e3f54c7b83a08bdc21a57b2
7
+ data.tar.gz: 11ce89bb941bf1e9f83d377fe1bc7b0da9a6e94cd7d7e93fb8b516348ceb7550e37966c2cbb6b4357f90bed927130a5a44658de12572ac0a37e1a2f270890f05
@@ -1,3 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.2
3
+ - 2.4.9
@@ -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", "~> 2.0"
27
- spec.add_dependency "roar-rails", "~> 1.0.2"
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", "~> 4.2.1"
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
- respond_with(
29
- error,
30
- status: error.status,
31
- location: nil, # for POST requests
32
- represent_with: HalApi::Errors::Representer
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)
@@ -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,5 +1,5 @@
1
1
  module HalApi
2
2
  module Rails
3
- VERSION = "0.7.0"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  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::Mapper.send(:include, Resources) if !Representable::Mapper.include?(Resources)
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 Resources
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?(binding, options)
29
- name = binding[:as].evaluate(self).to_s || binding.name
30
- embedded = !!binding[:embedded]
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
- # check if it should be zoomed, suppress if not
36
- !embed_zoomed?(name, binding[:zoom], options[: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, _args) do
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.7.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: 2019-09-09 00:00:00.000000000 Z
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: '2.0'
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: '2.0'
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.2
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.2
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: 4.2.1
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: 4.2.1
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
- rubyforge_project:
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