hal_api-rails 1.1.0 → 1.1.5

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
- SHA256:
3
- metadata.gz: 93692b389012f8d919478bd871f756f90118c517a1edde2a5ae6cbb463d644b1
4
- data.tar.gz: b15713d0ba0c1e005044dc48cc0a737066d89e1de84f1233e8072e17cdabc6d6
2
+ SHA1:
3
+ metadata.gz: a0316407b967e74603428b99f752626d6fa4a95f
4
+ data.tar.gz: 43b51a70a75c311fb0bd08196c7f6058ec9af7b2
5
5
  SHA512:
6
- metadata.gz: 572d57798b5240e8e33032de9b74492548f4901bb3fc74e9f2c40b65c59fea32d59b51a958e62087609365302ceb6fc349532920fb779a9d3d35aab841e97be5
7
- data.tar.gz: 8f2e81fe36e137287dab3492dc0636588c06ba3910fe9ddb682e3bfe42ddede2c4e79717229f12a6af8174bbde2fcf1cb222fbdc5aaadc1d64807f0c12e7e175
6
+ metadata.gz: a079010ce5c86f951791178cd5ab5516894ec76d7deb2de4e9a4b0570673083f1946ef0332d0c6ac10325564e08309474d22f5e48e4f8803d9890a2b023fb06c
7
+ data.tar.gz: 907505ccc54531e8a24ecd0180c170da9c2ddb3b25cd5e49372f7b8b0acf8456c22f3a1aee36229a82c6c695cc7dafec13e368fc985fe67c6d2ec588601431fe
@@ -0,0 +1 @@
1
+ 2.4.9
@@ -6,6 +6,6 @@ module HalApi
6
6
  require 'hal_api/responders/api_responder'
7
7
 
8
8
  def self.rails_major_version
9
- ::Rails.version.split('.')[0].to_i
9
+ ::Rails::VERSION::MAJOR
10
10
  end
11
11
  end
@@ -36,8 +36,7 @@ module HalApi::Controller
36
36
  private
37
37
 
38
38
  def set_accepts
39
- mime_comparator = case HalApi::rails_major_version
40
- when 5
39
+ mime_comparator = if HalApi::rails_major_version >= 5
41
40
  Mime[:html]
42
41
  else
43
42
  Mime::HTML
@@ -46,8 +45,7 @@ module HalApi::Controller
46
45
  end
47
46
 
48
47
  def env
49
- case HalApi.rails_major_version
50
- when 5
48
+ if HalApi.rails_major_version >= 5
51
49
  request.env
52
50
  else
53
51
  super
@@ -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
@@ -7,8 +7,7 @@ module HalApi::Controller::Exceptions
7
7
  extend ActiveSupport::Concern
8
8
 
9
9
  def respond_with_error(exception)
10
- wrapper = case HalApi.rails_major_version
11
- when 5
10
+ wrapper = if HalApi.rails_major_version >= 5
12
11
  ::ActionDispatch::ExceptionWrapper.new(ActiveSupport::BacktraceCleaner.new, exception)
13
12
  else
14
13
  ::ActionDispatch::ExceptionWrapper.new(request.env, exception)
@@ -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 = "1.1.0"
3
+ VERSION = '1.1.5'
4
4
  end
5
5
  end
@@ -12,11 +12,11 @@ module HalApi::Representer::CollectionPaging
12
12
  embeds :items, decorator: lambda{|*| item_decorator }, class: lambda{|*| item_class }, zoom: :always
13
13
 
14
14
  link :prev do
15
- href_url_helper(params.merge(page: represented.prev_page)) unless represented.first_page?
15
+ href_url_helper(params.merge(page: represented.prev_page)) if represented.prev_page
16
16
  end
17
17
 
18
18
  link :next do
19
- href_url_helper(params.merge(page: represented.next_page)) unless represented.last_page?
19
+ href_url_helper(params.merge(page: represented.next_page)) if represented.next_page
20
20
  end
21
21
 
22
22
  link :first do
@@ -10,15 +10,6 @@ module HalApi::Representer::Embeds
10
10
  Representable::Binding.send(:include, HalApiRailsRenderPipeline) if !Representable::Binding.include?(HalApiRailsRenderPipeline)
11
11
  end
12
12
 
13
- def normalize_options!(options)
14
- propagated_options, private_options = super(options)
15
-
16
- # we want this to propogate, and be available for `skip_property?`, so don't delete
17
- private_options[:zoom] = options[:zoom] if options.key?(:zoom)
18
-
19
- [propagated_options, private_options]
20
- end
21
-
22
13
  module HalApiRailsRenderPipeline
23
14
 
24
15
  def skip_property?(binding, private_options)
@@ -37,8 +28,6 @@ module HalApi::Representer::Embeds
37
28
 
38
29
  # embed if zoomed
39
30
  def suppress_embed?(input, options)
40
- user_options = options[:options]
41
-
42
31
  binding = options[:binding]
43
32
 
44
33
  # guard against non-hal representers
@@ -51,7 +40,8 @@ module HalApi::Representer::Embeds
51
40
  return false if !embedded
52
41
 
53
42
  ## check if it should be zoomed, suppress if not
54
- !embed_zoomed?(name, binding[:zoom], user_options[:zoom])
43
+ user_zooms = options[:options].try(:[], :user_options).try(:[], :zoom)
44
+ !embed_zoomed?(name, binding[:zoom], user_zooms)
55
45
  end
56
46
 
57
47
  def embed_zoomed?(name, zoom_def = nil, zoom_param = nil)
@@ -95,7 +85,9 @@ module HalApi::Representer::Embeds
95
85
  options[:getter] ||= ->(*) do
96
86
  cnt = send(name).count
97
87
  per = getter_per == :all ? cnt : getter_per
98
- if cnt <= per
88
+ if cnt == 0
89
+ items = send(name).page(1).per(Kaminari.config.default_per_page)
90
+ elsif cnt <= per
99
91
  items = Kaminari.paginate_array(send(name)).page(1).per(per)
100
92
  else
101
93
  items = send(name).page(1).per(per)
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: 1.1.0
4
+ version: 1.1.5
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: 2020-01-08 00:00:00.000000000 Z
12
+ date: 2021-01-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -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
@@ -254,7 +255,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
254
255
  - !ruby/object:Gem::Version
255
256
  version: '0'
256
257
  requirements: []
257
- rubygems_version: 3.0.3
258
+ rubyforge_project:
259
+ rubygems_version: 2.6.14.4
258
260
  signing_key:
259
261
  specification_version: 4
260
262
  summary: JSON HAL APIs on Rails in the style of PRX