hal_api-rails 1.1.4 → 1.2.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: 4d1af91c55bf42a53d4ecfe0c6ed673bd2856a57
4
- data.tar.gz: 0f0dac6e3b4e33821d9c20b0efe5fa1ead07b30e
2
+ SHA256:
3
+ metadata.gz: e4a383f7f5a7b49036f2f1bf9d213da2577984ef069bb9167f3ac01e7f439403
4
+ data.tar.gz: f8439a6fedd8b7d50cdda86eac60ec58e71380354cc2d02be7804c9964bc30d4
5
5
  SHA512:
6
- metadata.gz: 9bdfb40d56cfac300c5b2263ab25eec3b6162420cb417897c558b3e4bdfbd556acefe32da9387939ced5cb35046ad9295a6c7889881f385d996621914c0f5f3a
7
- data.tar.gz: 5c0745b9303bae2e66046fbda5ded266b0b642350968e5bbaf409a55d6c49186770217c22a2f80813e85f4f3e4b9e58b69c6a548689e44f55dba6c8def4b3e02
6
+ metadata.gz: 66af2d5541debb9174aedb920a52db996d792474722e9d1aca0c7dda083023dbec5332364dac991de00f54aa10e04b51c76da9bec32aeb6343af920e734225aa
7
+ data.tar.gz: e405ea5770a85801b2bd1cf5c5110ad7cc6a6c7b56940866dbfc2aaeec6a82cb4d4afb483d2794a9fd13f6fa01ca98f22179e87c0db82e8f19d362ba301414f8
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.4.9
1
+ 2.7.2
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in hal_api-rails.gemspec
data/Rakefile CHANGED
@@ -1,10 +1,13 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
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 << "test"
6
- t.libs << "lib"
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 :default => :test
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 "bundler/setup"
4
- require "hal_api/rails"
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 "irb"
14
+ require 'irb'
14
15
  IRB.start
@@ -1,36 +1,35 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
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 = "hal_api-rails"
8
+ spec.name = 'hal_api-rails'
8
9
  spec.version = HalApi::Rails::VERSION
9
- spec.authors = ["Chris Rhoden", "Andrew Kuklewicz"]
10
- spec.email = ["carhoden@gmail.com", "andrew@beginsinwonder.com"]
10
+ spec.authors = ['Chris Rhoden', 'Andrew Kuklewicz']
11
+ spec.email = ['carhoden@gmail.com', 'andrew@beginsinwonder.com']
11
12
 
12
- spec.summary = %q{JSON HAL APIs on Rails in the style of PRX}
13
- spec.description = %q{JSON HAL APIs on Rails in the style of PRX v4. Uses ROAR}
14
- spec.homepage = "https://www.github.com/PRX/"
15
- spec.license = "MIT"
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 = "exe"
19
+ spec.bindir = 'exe'
19
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
21
+ spec.require_paths = ['lib']
21
22
 
22
- spec.add_dependency "activemodel", ">= 3.0.0"
23
- spec.add_dependency "actionpack", ">= 3.0.0"
24
- spec.add_dependency "rack-test"
25
- spec.add_dependency "activesupport", ">= 3.0.0"
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 "bundler"
31
- spec.add_development_dependency "rake", "~> 10.0"
32
- spec.add_development_dependency "rails", "~> 5.2.4"
33
- spec.add_development_dependency "pry-byebug"
34
- spec.add_development_dependency "minitest"
35
- spec.add_development_dependency "kaminari"
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
- if !respond_to?(:authorize)
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,23 +7,27 @@ 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
12
- ::ActionDispatch::ExceptionWrapper.new(ActiveSupport::BacktraceCleaner.new, exception)
13
- else
14
- ::ActionDispatch::ExceptionWrapper.new(request.env, exception)
15
- end
16
-
17
- log_error(request.env, wrapper)
18
-
19
- error = exception
20
- if !error.is_a?(HalApi::Errors::ApiError)
21
- error = HalApi::Errors::ApiError.new(error.message).tap do |e|
22
- 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)
23
15
  end
24
- end
25
16
 
26
- notice_error(exception) if error.status >= 500
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
27
31
 
28
32
  respond_with(
29
33
  error,
@@ -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
@@ -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
- (klass && (klass != rep.class)) ? rep.becomes(klass) : rep
78
+ klass && (klass != rep.class) ? rep.becomes(klass) : rep
78
79
  end
79
80
 
80
81
  def count
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HalApi
2
4
  module Rails
3
- VERSION = '1.1.4'
5
+ VERSION = '1.2.0'
4
6
  end
5
7
  end
@@ -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
- self.instance_exec(options, &represented_url)
69
- elsif self.respond_to?(represented_url)
70
- self.send(represented_url, options)
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
@@ -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
- (klass && (klass != rep.class)) ? rep.becomes(klass) : rep
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}$/, "").dasherize
109
+ child = klass.name.underscore.gsub(/_#{parent}$/, '').dasherize
109
110
  [parent, child]
110
111
  else
111
112
  klass.name.underscore.dasherize
data/lib/hal_api.rb CHANGED
@@ -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
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.4
4
+ version: 1.2.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: 2020-06-10 00:00:00.000000000 Z
12
+ date: 2022-12-05 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: 3.0.0
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: 3.0.0
27
+ version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
- name: actionpack
29
+ name: activesupport
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 3.0.0
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: 3.0.0
41
+ version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
- name: rack-test
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: activesupport
57
+ name: roar-rails
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: 3.0.0
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: 3.0.0
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: multi_json
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: :runtime
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: bundler
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: rake
99
+ name: minitest
128
100
  requirement: !ruby/object:Gem::Requirement
129
101
  requirements:
130
- - - "~>"
102
+ - - ">="
131
103
  - !ruby/object:Gem::Version
132
- version: '10.0'
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: '10.0'
111
+ version: '0'
140
112
  - !ruby/object:Gem::Dependency
141
- name: rails
113
+ name: pry-byebug
142
114
  requirement: !ruby/object:Gem::Requirement
143
115
  requirements:
144
- - - "~>"
116
+ - - ">="
145
117
  - !ruby/object:Gem::Version
146
- version: 5.2.4
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: 5.2.4
125
+ version: '0'
154
126
  - !ruby/object:Gem::Dependency
155
- name: pry-byebug
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: minitest
141
+ name: rails
170
142
  requirement: !ruby/object:Gem::Requirement
171
143
  requirements:
172
- - - ">="
144
+ - - "~>"
173
145
  - !ruby/object:Gem::Version
174
- version: '0'
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: '0'
153
+ version: 5.2.4
182
154
  - !ruby/object:Gem::Dependency
183
- name: kaminari
155
+ name: rake
184
156
  requirement: !ruby/object:Gem::Requirement
185
157
  requirements:
186
158
  - - ">="
187
159
  - !ruby/object:Gem::Version
188
- version: '0'
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: '0'
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
@@ -255,8 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
255
227
  - !ruby/object:Gem::Version
256
228
  version: '0'
257
229
  requirements: []
258
- rubyforge_project:
259
- rubygems_version: 2.6.14.4
230
+ rubygems_version: 3.1.4
260
231
  signing_key:
261
232
  specification_version: 4
262
233
  summary: JSON HAL APIs on Rails in the style of PRX