camille 0.5.6 → 0.5.8

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: 991a6d473c51e10dce629da09a1b430ff316b448521bf8631b8994b358cdc809
4
- data.tar.gz: 34398f5bf1e5e2d2793de422d43dfd9c57b4f1eed9933cb3e99db91778e15ef9
3
+ metadata.gz: 60434d249fd905789f0c9fd812d097163cda296655c56fde57569269d8188e39
4
+ data.tar.gz: 422d993e72473270985d6ade710ae39e3ada83ef85942e83291176dc8bff9dcc
5
5
  SHA512:
6
- metadata.gz: 772f197217bc1ffdd29b432b3c615c34f13f286e694d33abec58a468722d3217c1d8ffcd893aadab57b3f2be4b57fbe693c08e7976d72f9c7aeee33bea67e837
7
- data.tar.gz: 679738f907ba017a94dc6e73b29ff82500765c207fb48a5da42c037e0ec9dbfb6155e4d26abc465b205271fbb1928ef29d677f1510c40f9a62dbb829e9e26d73
6
+ metadata.gz: 6561b6b4c62f85c22d28b27c9693a1dfe8a3cccaaf95251d3995b50b0457363ea82ef971fa03d10959bcf505ee0188b2189b6de5d3cd984930830bc2a9bdcd3e
7
+ data.tar.gz: 4266ecec3ab26f2e1af40b83fe60d337ed81b8fa6f953200c14f6e1dfb2ffe9519ea2d0519882b4790cc34cc1c7f84b18fb8481d0ec3cba88636c73236998761
data/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.8
4
+
5
+ ### Added
6
+
7
+ * `render` call with a status code other than 200 will skip the typecheck
8
+
9
+ ### Fixed
10
+
11
+ * `head 401` will no longer raise Camille::Controller::MissingRenderError
12
+
13
+ ## 0.5.7
14
+
15
+ ### Added
16
+
17
+ * Camille::Controller::MissingRenderError will now be raised if `render json:` is missing in action body
18
+ * ActionController::MissingExactTemplate is re-raised as Camille::Controller::MissingRenderError
19
+
3
20
  ## 0.5.6
4
21
 
5
22
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- camille (0.5.6)
4
+ camille (0.5.8)
5
5
  rails (>= 6.1, < 8)
6
6
 
7
7
  GEM
@@ -2,6 +2,7 @@ module Camille
2
2
  module Controller
3
3
  class TypeError < ::StandardError; end
4
4
  class ArgumentError < ::ArgumentError; end
5
+ class MissingRenderError < ::StandardError; end
5
6
 
6
7
  def camille_schema
7
8
  @camille_schema ||= Camille::Loader.controller_name_to_schema_map[self.class.name]
@@ -14,20 +15,25 @@ module Camille
14
15
  def render *args
15
16
  if endpoint = camille_endpoint
16
17
  render_options = args.last
17
- if value = render_options[:json]
18
- error, transformed = endpoint.response_type.transform_and_check(value)
19
- if error
20
- string_io = StringIO.new
21
- Camille::TypeErrorPrinter.new(error).print(string_io)
22
- raise TypeError.new("\nType check failed for response.\n#{string_io.string}")
23
- else
24
- if transformed.is_a? Hash
25
- transformed.deep_transform_keys!{|k| k.to_s.camelize(:lower)}
18
+ intended_status = render_options[:status] || 200
19
+ if intended_status == 200 || intended_status == :ok
20
+ if value = render_options[:json]
21
+ error, transformed = endpoint.response_type.transform_and_check(value)
22
+ if error
23
+ string_io = StringIO.new
24
+ Camille::TypeErrorPrinter.new(error).print(string_io)
25
+ raise TypeError.new("\nType check failed for response.\n#{string_io.string}")
26
+ else
27
+ if transformed.is_a? Hash
28
+ transformed.deep_transform_keys!{|k| k.to_s.camelize(:lower)}
29
+ end
30
+ super(json: transformed)
26
31
  end
27
- super(json: transformed)
32
+ else
33
+ raise ArgumentError.new("Expected key :json for `render` call.")
28
34
  end
29
35
  else
30
- raise ArgumentError.new("Expected key :json for `render` call.")
36
+ super
31
37
  end
32
38
  else
33
39
  super
@@ -37,12 +43,26 @@ module Camille
37
43
  def process_action(*)
38
44
  Camille::Loader.check_and_raise_exception
39
45
  if endpoint = camille_endpoint
40
- params.deep_transform_keys!{|key| key.to_s.underscore}
41
- super
46
+ begin
47
+ params.deep_transform_keys!{|key| key.to_s.underscore}
48
+ result = super
49
+ # When there's no `render` call, Rails will return status 204
50
+ if response.status == 204
51
+ raise_missing_render_error
52
+ end
53
+ result
54
+ rescue ActionController::MissingExactTemplate
55
+ raise_missing_render_error
56
+ end
42
57
  else
43
58
  super
44
59
  end
45
60
  end
46
61
 
62
+ private
63
+ def raise_missing_render_error
64
+ raise MissingRenderError.new("Expected `render json:` call in controller action body.")
65
+ end
66
+
47
67
  end
48
68
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Camille
4
- VERSION = "0.5.6"
4
+ VERSION = "0.5.8"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: camille
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - 辻彩
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-22 00:00:00.000000000 Z
11
+ date: 2023-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails