mini_api 0.1.0 → 0.1.2

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: b21a5cc35f98d6a21450a738d876b0c7fee94d36113e0c3999f15df17c59f643
4
- data.tar.gz: d60bf59a2ca1d64d4157fa46e9d770ed6b748e7895aa77bb2410936e09de91a6
3
+ metadata.gz: c6068dbc415de617d267b2e42d438eb85f36fdbbf0d083cf63efe86042130f96
4
+ data.tar.gz: 31f694de691b4c4d271d0d38273a5df7476aa6bb2118ecceadeca639ca7883f9
5
5
  SHA512:
6
- metadata.gz: dcb3b028b14506c7c15dd2df893c25af5dabdfd7f47ca8781c32ebaeb7cf2a3b6c5d17be9a2befeeb2c0c7cc996c774230ba1f9fe11b07464f1a50cd7a6e4a9a
7
- data.tar.gz: 2af62824d289dd78d9bb9e7a813a319179c56229ed6443e64746e65cf687e796e519a59d00c20c2f9745a3950d455111e0291eb6c7f05e5cd2cd6b635b9de7ab
6
+ metadata.gz: 287a2711d205b18d07fb6295e36bf132ef64953aa6d91a2f2f8699fdecaf82cc5fe0cd3a2292235f523ecf36ce6983c40b6d99a3a5d89418fe295ef4c834275c
7
+ data.tar.gz: 8045d230ca7765a976b34ec73b5fe9020bdf7b40f662de12a1e1b5a0e72cd2c446c3d859f91e0921467c179eb6a6b0aa2fdc2af39dc3ba169586937775934d2f
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Test Coverage](https://api.codeclimate.com/v1/badges/ec2939be693459b7ce4d/test_coverage)](https://codeclimate.com/github/leoncruz/api-responder/test_coverage)
4
4
 
5
5
  # Mini Api
6
- A gem to standardize json responses in Rails applications, highly inspired on [Responders](https:github.com/heartcombo/responders)
6
+ A gem to standardize json responses in Rails applications, highly inspired on [Responders](https://github.com/heartcombo/responders)
7
7
 
8
8
  ## Table of Contents
9
9
  - [Usage](#usage)
@@ -26,7 +26,7 @@ And then execute:
26
26
  $ bundle
27
27
  ```
28
28
 
29
- Your must install [Kaminari](https://github.com/kaminari/kaminari) to handle pagination
29
+ You must install [Kaminari](https://github.com/kaminari/kaminari) to handle pagination
30
30
  and [Active Model Serializers](http://github.com/rails-api/active_model_serializers) to handle data serialization
31
31
 
32
32
  ## Usage
@@ -23,9 +23,13 @@ module MiniApi
23
23
  if resource_has_errors?
24
24
  { errors: @resource.errors.messages }.merge(body)
25
25
  else
26
- { data: serialiable_body(@resource) }.merge(body)
26
+ { data: serialiable_body(@resource).as_json }.merge(body)
27
27
  end
28
28
 
29
+ # This is for an problem with ActiveModelSerializer that adds an error
30
+ # attribute when resource is an ActiveModel instance
31
+ body[:data] = body[:data].except('errors') if body[:data]&.key?('errors')
32
+
29
33
  @controller.render json: body, status: status_code
30
34
  end
31
35
 
@@ -40,9 +44,9 @@ module MiniApi
40
44
 
41
45
  return :unprocessable_entity if resource_has_errors?
42
46
 
43
- return :created if @resource.previously_new_record?
47
+ return :created if previously_new_record?
44
48
 
45
- return :no_content unless @resource.persisted?
49
+ return :no_content if destroyed?
46
50
 
47
51
  :ok
48
52
  end
@@ -57,5 +61,17 @@ module MiniApi
57
61
  default: ''
58
62
  )
59
63
  end
64
+
65
+ def previously_new_record?
66
+ return true if @resource.is_a?(ActiveRecord::Base) && @resource.previously_new_record?
67
+
68
+ false
69
+ end
70
+
71
+ def destroyed?
72
+ return true if @resource.is_a?(ActiveRecord::Base) && !@resource.persisted?
73
+
74
+ false
75
+ end
60
76
  end
61
77
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MiniApi
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.2'
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.0
4
+ version: 0.1.2
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-17 00:00:00.000000000 Z
11
+ date: 2023-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -48,6 +48,10 @@ homepage:
48
48
  licenses:
49
49
  - MIT
50
50
  metadata:
51
+ homepage_uri: https://github.com/leoncruz/mini_api
52
+ documentation_uri: https://www.rubydoc.info/gems/mini_api/
53
+ source_code_uri: https://github.com/leoncruz/mini_api
54
+ bug_tracker_uri: https://github.com/leoncruz/mini_api/issues
51
55
  rubygems_mfa_required: 'true'
52
56
  post_install_message:
53
57
  rdoc_options: []