mini_api 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/mini_api/model_responder.rb +7 -1
- data/lib/mini_api/serialization.rb +6 -8
- data/lib/mini_api/translation/message.rb +1 -1
- data/lib/mini_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5d0ed96803b2a46a7e13aa3705c1b06dd2ffa2a1474d4d646e2a4deaad2aa8c
|
4
|
+
data.tar.gz: 22d55b43c092628891398ba8eb4238f4bcea484e7705936e0e25b545f61dc27f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d15be33457f31c83030d04f4d52e2b859cd917e2753393b55add61c00654e1e8729311a00a21de25fc44488a26b5c56e99abd9bfedcd85b6894644a699e5105d
|
7
|
+
data.tar.gz: 6fc53a392a57940498ee5a4b205e5388e6b409ebca9bc81b1323ce4dd7a709460d91044d551fd07510a4b82c04ab165fb0bcf420a24e410f2ad37d5937945100
|
data/README.md
CHANGED
@@ -204,6 +204,11 @@ You can add translation based on models, changing the `action` key for your mode
|
|
204
204
|
It is possible define a translation based on controller, useful if you use nested controlers. The path is:
|
205
205
|
`min_api.messages.controller_name.action_name.alert`
|
206
206
|
|
207
|
+
If you would like to send the message as `null`, has to use the `:empty` symbol, like:
|
208
|
+
```ruby
|
209
|
+
render_json @object, message: :empty
|
210
|
+
```
|
211
|
+
|
207
212
|
### Transform keys
|
208
213
|
|
209
214
|
It is possible to transform the keys of request and response. By default, will transform to `snake_case`, but the possible values are `snake_case`, `camel_lower` and `camel_case`
|
@@ -19,7 +19,7 @@ module MiniApi
|
|
19
19
|
def respond
|
20
20
|
body = {
|
21
21
|
success: resource_has_errors? == false,
|
22
|
-
message:
|
22
|
+
message: message
|
23
23
|
}
|
24
24
|
|
25
25
|
body =
|
@@ -36,6 +36,12 @@ module MiniApi
|
|
36
36
|
|
37
37
|
private
|
38
38
|
|
39
|
+
def message
|
40
|
+
return if @options[:message] == :empty
|
41
|
+
|
42
|
+
@options[:message] || i18n_message
|
43
|
+
end
|
44
|
+
|
39
45
|
def resource_has_errors?
|
40
46
|
!@resource.errors.empty?
|
41
47
|
end
|
@@ -6,7 +6,8 @@ module MiniApi
|
|
6
6
|
module Serialization
|
7
7
|
# This method search by serializer using the module parents of controller.
|
8
8
|
# With this, is possible define serializers for the same resource
|
9
|
-
# in different controller scopes
|
9
|
+
# in different controller scopes.
|
10
|
+
# If the resource class does not have a resource, will be use the default `as_json` method
|
10
11
|
def serialiable_body(resource)
|
11
12
|
controller_scope = @controller.class.module_parents
|
12
13
|
|
@@ -24,12 +25,14 @@ module MiniApi
|
|
24
25
|
|
25
26
|
break serializer_class if serializer_class
|
26
27
|
|
27
|
-
break
|
28
|
+
break if controller_scope.empty?
|
28
29
|
|
29
30
|
controller_scope.shift
|
30
31
|
end
|
31
32
|
|
32
|
-
serializer_class.new(resource)
|
33
|
+
return serializer_class.new(resource) if serializer_class
|
34
|
+
|
35
|
+
resource
|
33
36
|
end
|
34
37
|
|
35
38
|
# Search by the nested class +Error+ on serializer
|
@@ -41,10 +44,5 @@ module MiniApi
|
|
41
44
|
|
42
45
|
"#{error_serializer.class}::Error".safe_constantize
|
43
46
|
end
|
44
|
-
|
45
|
-
# Empty serializer class for when resource does not have a custom class
|
46
|
-
class DefaultResource
|
47
|
-
include Alba::Resource
|
48
|
-
end
|
49
47
|
end
|
50
48
|
end
|
data/lib/mini_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leon Cruz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: alba
|