shark-on-lambda 2.0.0.rc1 → 2.1.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
2
  SHA256:
3
- metadata.gz: 642998e593034c083639724031920edfe7568de50d276cc3c58932c099d94a0e
4
- data.tar.gz: 8101e725e3ef4f710422625726f87c7a324e986b9eb6184a988e0fdd3812bdda
3
+ metadata.gz: 60c364794145282c0c04213abbf976f245f696442d827b2149e0ccaa1fe95d08
4
+ data.tar.gz: b1360ec675a7267f41ce6d2d385f2a5c5cae8cb87c93a958c79b8c326b4a635e
5
5
  SHA512:
6
- metadata.gz: d23eac59ce2797aac609444509d571a54ffb22024f11070a54dd43d600ceeeb2b527e421c1c9463ac08cceb4fa2b9ad6a366e496cebb47c2873276e9abf4a9ec
7
- data.tar.gz: 8932eeb3134b88fb0da09b35a3a70eb1b4d1bfb5b2a1f522b9f4bc23c07890b4c6c9cd061374aebf4eb80c09695ef69420da95cc7f608c415b81692724f41e56
6
+ metadata.gz: 48d8ef1d01c5cfd04fc2c40effca3c53f29bb2b3deaecb8f240a545829425e279274e570e9ace27948a4ec738da115ed5c69cef4418e2023aa8dc99eedf240e2
7
+ data.tar.gz: ec1d9ce4bcb7b62be4f986be8763f31c3879ffc9b1eb800fe676a03df6a93f9313657696486a6a5fe993784fd8c5f601ed398d4c052b350fc02dde2d86f4624b
data/.rubocop.yml CHANGED
@@ -10,10 +10,15 @@ Metrics/BlockLength:
10
10
  Layout/LineLength:
11
11
  Max: 80
12
12
 
13
+ Lint/EmptyClass:
14
+ Enabled: false
15
+
13
16
  Naming/FileName:
14
17
  Exclude:
15
18
  - lib/shark-on-lambda.rb
16
19
  - spec/shark-on-lambda_spec.rb
20
+ Naming/VariableNumber:
21
+ EnforcedStyle: snake_case
17
22
 
18
23
  # TODO: Add documentation and remove the Style/Documentation exception.
19
24
  Style/Documentation:
@@ -2,6 +2,10 @@
2
2
 
3
3
  #### Unreleased
4
4
 
5
+ #### 2.1.0
6
+ - [Fix] `SharkOnLambda::BaseController#render` does not set content type `application/vnd.api+json`
7
+ - [Fix] `:jsonapi` Renderer sets content type `application/vnd.api+json` correctly
8
+
5
9
  #### 2.0.0
6
10
  - [Deprecate] Requiring `shark-on-lambda` is marked as deprecated in favour of requiring `shark_on_lambda`.
7
11
  - [Break] `SharkOnLambda::Dispatcher` was removed in favour of routing via `ActionDispatch::Routing`.
@@ -9,6 +13,8 @@
9
13
  - [Break] `SharkOnLambda::JsonapiController` was removed.
10
14
  - [Break] Support for `path_parameters` in RSpec helpers was removed.
11
15
  - [Break] Configuration files are not loaded automatically anymore.
16
+ - Added `SharkOnLambda::Cacheable`.
17
+ - Added `SharkOnLambda.cache` and `SharkOnLambda.global_cache`.
12
18
  - Added support for routing.
13
19
  - Use `rack-on-lambda` as an adapter for events from the (REST API flavoured) API Gateway.
14
20
 
@@ -22,7 +28,7 @@
22
28
  - [Break] Remove the `ApiGateway` namespace, move all items from that namespace up by one level.
23
29
  - [Break] Remove build rake tasks.
24
30
  - [Added `SharkOnLambda::LambdaLogger`](https://www.pivotaltracker.com/story/show/169573932)
25
- - Added support for Rack-compatible middleware.
31
+ - Added support for Rack-compatible middleware.
26
32
  - `SharkOnLambda::BaseController` now acts more like `ActionController::BaseController`.
27
33
  - Support `ActiveModel::Errors` nested validation errors.
28
34
  - Added `SharkOnLambda::RSpec::Helpers` and `SharkOnLambda::RSpec::JsonapiHelpers`.
@@ -4,7 +4,7 @@ require 'active_support/core_ext/string'
4
4
  require 'active_support/deprecation'
5
5
 
6
6
  deprecation_message = <<-MESSAGE.squish
7
- Requiring `shark-on-lambda` is deprecated and will be removed in version 3.0.
7
+ Requiring `shark-on-lambda` is deprecated and will be removed in version 3.
8
8
  Please require `shark_on_lambda` instead.
9
9
  MESSAGE
10
10
  ActiveSupport::Deprecation.warn(deprecation_message, caller(2))
@@ -38,7 +38,7 @@ module SharkOnLambda
38
38
  class << self
39
39
  extend Forwardable
40
40
 
41
- attr_writer :application, :env, :logger
41
+ attr_writer :application, :cache, :env, :global_cache, :logger
42
42
 
43
43
  def_instance_delegators :application, :initialize!, :root
44
44
 
@@ -50,10 +50,18 @@ module SharkOnLambda
50
50
  application.config
51
51
  end
52
52
 
53
+ def cache
54
+ @cache ||= ActiveSupport::Cache::NullStore.new
55
+ end
56
+
53
57
  def env
54
58
  @env || ENV['STAGE'].presence || 'development'
55
59
  end
56
60
 
61
+ def global_cache
62
+ @global_cache ||= ActiveSupport::Cache::NullStore.new
63
+ end
64
+
57
65
  def logger
58
66
  @logger ||= Logger.new($stdout)
59
67
  end
@@ -37,7 +37,7 @@ module SharkOnLambda
37
37
  end
38
38
 
39
39
  def config_for(name, env: SharkOnLambda.env)
40
- config = load_config_file(name, env: env)
40
+ config = load_config_file(name, env: env, fail_with_exception: true)
41
41
  config.deep_merge(load_config_file("#{name}.local", env: env))
42
42
  end
43
43
 
@@ -53,10 +53,12 @@ module SharkOnLambda
53
53
  @routes = ActionDispatch::Routing::RouteSet.new_with_config(router_config)
54
54
  end
55
55
 
56
- def load_config_file(name, env:)
56
+ def load_config_file(name, env:, fail_with_exception: false)
57
57
  filename = "#{name}.yml"
58
58
  config_file = SharkOnLambda.root.join('config', filename)
59
59
  unless config_file.exist?
60
+ return {} unless fail_with_exception
61
+
60
62
  raise ArgumentError,
61
63
  "Could not load configuration. No such file - #{config_file}"
62
64
  end
@@ -22,7 +22,7 @@ module SharkOnLambda
22
22
  end
23
23
 
24
24
  ActionController::Renderers.add :jsonapi do |object, options|
25
- response.set_header('content-type', 'application/vnd.api+json')
25
+ response.content_type = 'application/vnd.api+json; charset=utf-8'
26
26
  return { data: {} }.to_json if object.nil?
27
27
 
28
28
  jsonapi_renderer = JsonapiRenderer.new(object)
@@ -52,15 +52,6 @@ module SharkOnLambda
52
52
  self.response_body = no_body? ? nil : { data: {} }.to_json
53
53
  end
54
54
 
55
- def render(object, options = {})
56
- options.merge!(
57
- jsonapi: object,
58
- content_type: 'application/vnd.api+json'
59
- )
60
-
61
- super(options)
62
- end
63
-
64
55
  private
65
56
 
66
57
  def no_body?
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SharkOnLambda
4
+ module Cacheable
5
+ delegate :cache, :global_cache, to: SharkOnLambda
6
+
7
+ def cache_duration(item)
8
+ cache_durations[item] || cache_durations[:default]
9
+ end
10
+
11
+ private
12
+
13
+ def cache_durations
14
+ return @cache_durations if defined?(@cache_durations)
15
+
16
+ settings = SharkOnLambda.application.config_for(:settings) || {}
17
+ @cache_durations = settings.fetch(:cache_durations, {})
18
+ @cache_durations = @cache_durations.with_indifferent_access
19
+ end
20
+ end
21
+ end
@@ -36,7 +36,7 @@ module SharkOnLambda
36
36
  end
37
37
  class_name_parts = message.to_s.split(/\s+/)
38
38
  class_name_parts.map! { |word| word.gsub(/[^a-z]/i, '').capitalize }
39
- class_name = class_name_parts.join('')
39
+ class_name = class_name_parts.join
40
40
  const_set(class_name, error_class)
41
41
 
42
42
  [status_code, error_class]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SharkOnLambda
4
- VERSION = '2.0.0.rc1'
4
+ VERSION = '2.1.0'
5
5
  end
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency 'activesupport', '~> 6.0.0'
37
37
  spec.add_dependency 'jsonapi-rb', '~> 0.5.0'
38
38
  spec.add_dependency 'rack', '>= 2.0.8', '< 3'
39
- spec.add_dependency 'rack-on-lambda', '~> 1.0'
39
+ spec.add_dependency 'rack-on-lambda', '~> 1.0', '>= 1.0.1'
40
40
  spec.add_dependency 'zeitwerk', '~> 2.3'
41
41
 
42
42
  # TODO: Do we really need `activemodel`?
@@ -48,7 +48,7 @@ Gem::Specification.new do |spec|
48
48
  spec.add_development_dependency 'pry-byebug'
49
49
  spec.add_development_dependency 'rake'
50
50
  spec.add_development_dependency 'rspec'
51
- spec.add_development_dependency 'rubocop'
51
+ spec.add_development_dependency 'rubocop', '1.11.0'
52
52
  spec.add_development_dependency 'simplecov'
53
53
  spec.add_development_dependency 'yard'
54
54
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shark-on-lambda
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.rc1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Huy Dinh
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-23 00:00:00.000000000 Z
11
+ date: 2021-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -79,6 +79,9 @@ dependencies:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
81
  version: '1.0'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 1.0.1
82
85
  type: :runtime
83
86
  prerelease: false
84
87
  version_requirements: !ruby/object:Gem::Requirement
@@ -86,6 +89,9 @@ dependencies:
86
89
  - - "~>"
87
90
  - !ruby/object:Gem::Version
88
91
  version: '1.0'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 1.0.1
89
95
  - !ruby/object:Gem::Dependency
90
96
  name: zeitwerk
91
97
  requirement: !ruby/object:Gem::Requirement
@@ -202,16 +208,16 @@ dependencies:
202
208
  name: rubocop
203
209
  requirement: !ruby/object:Gem::Requirement
204
210
  requirements:
205
- - - ">="
211
+ - - '='
206
212
  - !ruby/object:Gem::Version
207
- version: '0'
213
+ version: 1.11.0
208
214
  type: :development
209
215
  prerelease: false
210
216
  version_requirements: !ruby/object:Gem::Requirement
211
217
  requirements:
212
- - - ">="
218
+ - - '='
213
219
  - !ruby/object:Gem::Version
214
- version: '0'
220
+ version: 1.11.0
215
221
  - !ruby/object:Gem::Dependency
216
222
  name: simplecov
217
223
  requirement: !ruby/object:Gem::Requirement
@@ -253,13 +259,13 @@ files:
253
259
  - ".gitignore"
254
260
  - ".rspec"
255
261
  - ".rubocop.yml"
262
+ - CHANGELOG.md
256
263
  - CODE_OF_CONDUCT.md
257
264
  - LICENSE.txt
258
265
  - README.md
259
266
  - Rakefile
260
267
  - bin/console
261
268
  - bin/setup
262
- - changelog.md
263
269
  - doc/upgrade-from-0.6.x-to-1.x.md
264
270
  - gems.rb
265
271
  - lib/shark-on-lambda.rb
@@ -267,6 +273,7 @@ files:
267
273
  - lib/shark_on_lambda/api_gateway_handler.rb
268
274
  - lib/shark_on_lambda/application.rb
269
275
  - lib/shark_on_lambda/base_controller.rb
276
+ - lib/shark_on_lambda/cacheable.rb
270
277
  - lib/shark_on_lambda/configuration.rb
271
278
  - lib/shark_on_lambda/errors/base.rb
272
279
  - lib/shark_on_lambda/errors/base_serializer.rb
@@ -301,9 +308,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
301
308
  version: '2.5'
302
309
  required_rubygems_version: !ruby/object:Gem::Requirement
303
310
  requirements:
304
- - - ">"
311
+ - - ">="
305
312
  - !ruby/object:Gem::Version
306
- version: 1.3.1
313
+ version: '0'
307
314
  requirements: []
308
315
  rubyforge_project:
309
316
  rubygems_version: 2.7.6.2