camille 0.5.5 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/Gemfile.lock +1 -1
- data/README.md +4 -2
- data/lib/camille/controller.rb +17 -2
- data/lib/camille/types/record.rb +58 -0
- data/lib/camille/version.rb +1 -1
- data/lib/camille.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ff47e3a7fdcb5ef28cca7bc5ce3989900c82d7eb0d94af77a00e0b0c4ac9b3d
|
4
|
+
data.tar.gz: 7885520d31b5b0a4f339cc24e5993ea1d8e1d637029a018b5dcb144060e72965
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c990d3326e3271092647bd2ccdbc9ddf213e0f6200c872f0d398c4fb5306670c7e9993e4e48c82dab84a97ea4a8b3200ad100475c4a9243758e94ea211df681
|
7
|
+
data.tar.gz: c21e9542119b194dac81e446574c582fcf16a98a7fbeaeeba33e083518b3070b826a4db20596ff22fb5b18f1b8e64161056e10f71309a3309ab3213c8da9ba4d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.5.7
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
* Camille::Controller::MissingRenderError will now be raised if `render json:` is missing in action body
|
8
|
+
* ActionController::MissingExactTemplate is re-raised as Camille::Controller::MissingRenderError
|
9
|
+
|
10
|
+
## 0.5.6
|
11
|
+
|
12
|
+
### Added
|
13
|
+
|
14
|
+
* Added record type
|
15
|
+
|
16
|
+
## 0.5.5
|
17
|
+
|
18
|
+
### Added
|
19
|
+
|
20
|
+
* Added case conversion check for object keys.
|
21
|
+
|
3
22
|
## 0.5.4
|
4
23
|
|
5
24
|
### Added
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -163,9 +163,11 @@ params(
|
|
163
163
|
boolean_literal: false,
|
164
164
|
# a custom type we defined above
|
165
165
|
product: Product,
|
166
|
-
# Pick and Omit
|
166
|
+
# Pick and Omit accept a type and an array of symbols
|
167
167
|
pick: Pick[{a: 1, b: 2}, [:a, :b]],
|
168
|
-
omit: Omit[Product, [:id]]
|
168
|
+
omit: Omit[Product, [:id]],
|
169
|
+
# Record accepts a key type and a value type
|
170
|
+
record: Record[Number, String]
|
169
171
|
)
|
170
172
|
```
|
171
173
|
|
data/lib/camille/controller.rb
CHANGED
@@ -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]
|
@@ -24,6 +25,7 @@ module Camille
|
|
24
25
|
if transformed.is_a? Hash
|
25
26
|
transformed.deep_transform_keys!{|k| k.to_s.camelize(:lower)}
|
26
27
|
end
|
28
|
+
@camille_rendered = true
|
27
29
|
super(json: transformed)
|
28
30
|
end
|
29
31
|
else
|
@@ -37,12 +39,25 @@ module Camille
|
|
37
39
|
def process_action(*)
|
38
40
|
Camille::Loader.check_and_raise_exception
|
39
41
|
if endpoint = camille_endpoint
|
40
|
-
|
41
|
-
|
42
|
+
begin
|
43
|
+
params.deep_transform_keys!{|key| key.to_s.underscore}
|
44
|
+
result = super
|
45
|
+
unless @camille_rendered
|
46
|
+
raise_missing_render_error
|
47
|
+
end
|
48
|
+
result
|
49
|
+
rescue ActionController::MissingExactTemplate
|
50
|
+
raise_missing_render_error
|
51
|
+
end
|
42
52
|
else
|
43
53
|
super
|
44
54
|
end
|
45
55
|
end
|
46
56
|
|
57
|
+
private
|
58
|
+
def raise_missing_render_error
|
59
|
+
raise MissingRenderError.new("Expected `render json:` call in controller action body.")
|
60
|
+
end
|
61
|
+
|
47
62
|
end
|
48
63
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Camille
|
2
|
+
module Types
|
3
|
+
class Record < Camille::BasicType
|
4
|
+
attr_reader :left, :right
|
5
|
+
attr_reader :key, :value
|
6
|
+
|
7
|
+
def initialize key, value
|
8
|
+
@key = Camille::Type.instance key
|
9
|
+
@value = Camille::Type.instance value
|
10
|
+
end
|
11
|
+
|
12
|
+
def transform_and_check value
|
13
|
+
if value.is_a? ::Hash
|
14
|
+
|
15
|
+
transform_and_check_results = value.map.with_index do |(k, v), index|
|
16
|
+
[index, transform_and_check_pair(k, v)]
|
17
|
+
end
|
18
|
+
|
19
|
+
errors = transform_and_check_results.map do |index, (error, transformed)|
|
20
|
+
["record[#{index}]", error]
|
21
|
+
end.select{|x| x[1]}
|
22
|
+
|
23
|
+
if errors.empty?
|
24
|
+
transformed = transform_and_check_results.map{|_, (_, transformed)| transformed}.to_h
|
25
|
+
[nil, transformed]
|
26
|
+
else
|
27
|
+
[Camille::TypeError.new(**errors.to_h), nil]
|
28
|
+
end
|
29
|
+
else
|
30
|
+
[Camille::TypeError.new("Expected hash, got #{value.inspect}."), nil]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.[] key, value
|
35
|
+
self.new key, value
|
36
|
+
end
|
37
|
+
|
38
|
+
def literal
|
39
|
+
"Record<#{@key.literal}, #{@value.literal}>"
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def transform_and_check_pair key, value
|
44
|
+
key_error, key_transformed = @key.transform_and_check key
|
45
|
+
value_error, value_transformed = @value.transform_and_check value
|
46
|
+
|
47
|
+
if key_error.nil? && value_error.nil?
|
48
|
+
[nil, [key_transformed, value_transformed]]
|
49
|
+
else
|
50
|
+
errors = [['record.key', key_error], ['record.value', value_error]].select{|x| x[1]}.to_h
|
51
|
+
|
52
|
+
error = Camille::TypeError.new(**errors)
|
53
|
+
[error, nil]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/camille/version.rb
CHANGED
data/lib/camille.rb
CHANGED
@@ -21,6 +21,7 @@ require_relative "camille/types/boolean_literal"
|
|
21
21
|
require_relative "camille/pick_and_omit"
|
22
22
|
require_relative "camille/types/pick"
|
23
23
|
require_relative "camille/types/omit"
|
24
|
+
require_relative "camille/types/record"
|
24
25
|
require_relative "camille/type"
|
25
26
|
require_relative "camille/type_error"
|
26
27
|
require_relative "camille/type_error_printer"
|
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.
|
4
|
+
version: 0.5.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 辻彩
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/camille/types/object.rb
|
85
85
|
- lib/camille/types/omit.rb
|
86
86
|
- lib/camille/types/pick.rb
|
87
|
+
- lib/camille/types/record.rb
|
87
88
|
- lib/camille/types/string.rb
|
88
89
|
- lib/camille/types/string_literal.rb
|
89
90
|
- lib/camille/types/tuple.rb
|