hal_api-rails 0.7.0 → 1.1.3

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
  SHA1:
3
- metadata.gz: e8ca09414db3082766a5b86ee83310563af05628
4
- data.tar.gz: 002aceca75878356759760d73f5dd68cd6dc03d4
3
+ metadata.gz: 6582376382b79d5798d11a52efd471b1045a6f9b
4
+ data.tar.gz: a42dc149632a9204917a52324a77eb84d8e8a6aa
5
5
  SHA512:
6
- metadata.gz: 25f710db7f628fbbd0b708c06e04f4b1f2eb8335ecbb8a48311e68ac4259ad5cfe80d5bbbd02df41d55ea846c8b0d4423055cf1fcbe64f09e37217d1d7c92d33
7
- data.tar.gz: df4c7da616d62d01b5dddeb031b2e2c7bd94b61e6399452ab17fbe7a43ffe12c1909e5b138821de4e74dad83ac98295355a1550729a5a4220508f24faaa9f849
6
+ metadata.gz: 15d29307746ba71e20696715b029bd6596eedf0e2c2daec49cac50f96cfd7e85b2fdb88973ff39420547e0ca84e941fc7ff3129cb71aeaad7536190b9f95cffa
7
+ data.tar.gz: 9790fb8b62284d9292bb8fb6e29cbeac080c9d76511b1bceb9305fb26a6b99439c25597b53334e1bb2325eab3d0cb2e8d9b57f800f39a5b467f9079621aedfec
@@ -0,0 +1 @@
1
+ 2.4.9
@@ -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"
@@ -71,7 +71,9 @@ module HalApi::Controller::Actions
71
71
 
72
72
  def valid_params_for_action(action)
73
73
  (params.permit(*self.class.valid_params_list(action)) || {}).tap do |p|
74
- p[:zoom] = zoom_param if zoom_param
74
+ if zoom_param
75
+ p[:user_options] = (p[:user_options] || {}).merge(zoom: zoom_param)
76
+ end
75
77
  end.
76
78
  to_h
77
79
  end
@@ -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)
@@ -102,7 +102,11 @@ module HalApi::Controller::Resources
102
102
  end
103
103
 
104
104
  def paged(arel)
105
- arel.page(params[:page]).per(params[:per])
105
+ if params[:per].to_i <= 0
106
+ arel.page(params[:page]).per(Kaminari.config.default_per_page)
107
+ else
108
+ arel.page(params[:page]).per(params[:per])
109
+ end
106
110
  end
107
111
 
108
112
  def scoped(res)
@@ -1,5 +1,5 @@
1
1
  module HalApi
2
2
  module Rails
3
- VERSION = "0.7.0"
3
+ VERSION = '1.1.3'
4
4
  end
5
5
  end
@@ -1,39 +1,47 @@
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
- def normalize_options!(options)
13
- propagated_options, private_options = super(options)
14
-
15
- # we want this to propogate, and be available for `skip_property?`, so don't delete
16
- private_options[:zoom] = options[:zoom] if options.key?(:zoom)
17
-
18
- [propagated_options, private_options]
19
- end
20
-
21
- module Resources
13
+ module HalApiRailsRenderPipeline
22
14
 
23
15
  def skip_property?(binding, private_options)
24
16
  super(binding, private_options) || suppress_embed?(binding, private_options)
25
17
  end
26
18
 
19
+ def render_functions
20
+ funcs = super
21
+ f = ->(input, options) do
22
+ if suppress_embed?(input, options)
23
+ return Representable::Pipeline::Stop
24
+ end
25
+ end
26
+ [f] + funcs
27
+ end
28
+
27
29
  # embed if zoomed
28
- def suppress_embed?(binding, options)
29
- name = binding[:as].evaluate(self).to_s || binding.name
30
- embedded = !!binding[:embedded]
30
+ def suppress_embed?(input, options)
31
+ binding = options[:binding]
32
+
33
+ # guard against non-hal representers
34
+ return false unless binding[:as].present?
35
+
36
+ name = binding.evaluate_option(:as, input, options)
37
+
38
+ embedded = binding[:embedded]
31
39
 
32
- # not embedded, return false - nothing to suppress
33
40
  return false if !embedded
34
41
 
35
- # check if it should be zoomed, suppress if not
36
- !embed_zoomed?(name, binding[:zoom], options[:zoom])
42
+ ## check if it should be zoomed, suppress if not
43
+ user_zooms = options[:options].try(:[], :user_options).try(:[], :zoom)
44
+ !embed_zoomed?(name, binding[:zoom], user_zooms)
37
45
  end
38
46
 
39
47
  def embed_zoomed?(name, zoom_def = nil, zoom_param = nil)
@@ -77,7 +85,9 @@ module HalApi::Representer::Embeds
77
85
  options[:getter] ||= ->(*) do
78
86
  cnt = send(name).count
79
87
  per = getter_per == :all ? cnt : getter_per
80
- if cnt <= per
88
+ if cnt == 0
89
+ items = send(name).page(1).per(Kaminari.config.default_per_page)
90
+ elsif cnt <= per
81
91
  items = Kaminari.paginate_array(send(name)).page(1).per(per)
82
92
  else
83
93
  items = send(name).page(1).per(per)
@@ -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.1.3
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-06-09 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
@@ -202,6 +202,7 @@ extensions: []
202
202
  extra_rdoc_files: []
203
203
  files:
204
204
  - ".gitignore"
205
+ - ".ruby-version"
205
206
  - ".travis.yml"
206
207
  - CODE_OF_CONDUCT.md
207
208
  - Gemfile
@@ -255,7 +256,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
255
256
  version: '0'
256
257
  requirements: []
257
258
  rubyforge_project:
258
- rubygems_version: 2.5.2.3
259
+ rubygems_version: 2.6.14.4
259
260
  signing_key:
260
261
  specification_version: 4
261
262
  summary: JSON HAL APIs on Rails in the style of PRX