mini_api 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fbf83309b4f2fccd1e62e7e53cb0bf955472f68f1aa0a5a57517976c478fc97
4
- data.tar.gz: 343a0d838eeb146e2c35dd7a483872825b330caa0afd54267ed34e9fe164f13a
3
+ metadata.gz: c5d0ed96803b2a46a7e13aa3705c1b06dd2ffa2a1474d4d646e2a4deaad2aa8c
4
+ data.tar.gz: 22d55b43c092628891398ba8eb4238f4bcea484e7705936e0e25b545f61dc27f
5
5
  SHA512:
6
- metadata.gz: 76fa5b3615b1a7dee108f5c236356398cde720a9f281314c3dca45616eaf4cc1d7c0baf5a02b991219bfb7d49c7937f43a2a29514749d064ec4b4ad33d55aa92
7
- data.tar.gz: ee55e68cde7652108534bd1d62c9462303b64e92b62be836b240cacb4cb1354983e7818d46dbe25da61ea7c69f638201b27c393498a076609433e94c069e44ff
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: @options[:message] || 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 DefaultResource if controller_scope.empty?
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
@@ -33,7 +33,7 @@ module MiniApi
33
33
  # alert: '%{resource_name} não pôde ser criado.'
34
34
 
35
35
  module Message
36
- def message
36
+ def i18n_message
37
37
  kind = @resource.errors.empty? ? 'notice' : 'alert'
38
38
 
39
39
  I18n.t(
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MiniApi
4
- VERSION = '0.1.5'
4
+ VERSION = '0.1.6'
5
5
  end
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.5
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-06-26 00:00:00.000000000 Z
11
+ date: 2023-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: alba