jsonapi_responses 0.1.1 → 0.1.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90ed37460147f9a795a6297a734d47b55a7bcb4bcbb98025c294684fc9ad56c9
|
4
|
+
data.tar.gz: cbac58151075f09b2b62a2cecf921722f476970c6ac3ea3013869038fea9386e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd2261e66bc0f85192da72a1a6386bac3623776e32b0dba1708c9d57cb001a3f990dbbede2c34125af9eefe2fe4bb8366f0f7bab359bf2ee971b402fa09487cc
|
7
|
+
data.tar.gz: 6af64f7c8dc1ac440a3b8ca1acec86bf18556cad62b0dab4fe59689431e86d3a54cc1d6ce306170e9a1eaf22f5496eb450a953fef6d5c34754cbf6a607213c22
|
@@ -1,14 +1,10 @@
|
|
1
1
|
# lib/jsonapi_responses/engine.rb
|
2
2
|
require 'active_support'
|
3
|
+
require 'rails'
|
4
|
+
|
3
5
|
module JsonapiResponses
|
4
6
|
# Define Engine
|
5
7
|
class Engine < ::Rails::Engine
|
6
8
|
isolate_namespace JsonapiResponses
|
7
|
-
|
8
|
-
initializer 'jsonapi_responses.initialize' do
|
9
|
-
Rails.application.config.to_prepare do
|
10
|
-
ApplicationController.include JsonapiResponses::Respondable
|
11
|
-
end
|
12
|
-
end
|
13
9
|
end
|
14
10
|
end
|
@@ -1,17 +1,19 @@
|
|
1
1
|
require 'active_support/concern'
|
2
2
|
require 'jsonapi_responses/serializable'
|
3
|
+
require 'jsonapi_responses/user_context_provider'
|
3
4
|
|
4
5
|
module JsonapiResponses
|
5
6
|
# Respondable module
|
6
7
|
module Respondable
|
7
8
|
extend ActiveSupport::Concern
|
8
9
|
include JsonapiResponses::Serializable
|
10
|
+
include JsonapiResponses::UserContextProvider
|
9
11
|
|
10
12
|
private
|
11
13
|
|
12
|
-
def
|
14
|
+
def render_with(record, options = {})
|
13
15
|
action = options[:action] || action_name.to_sym
|
14
|
-
context = options[:context] || {}
|
16
|
+
context = (options[:context] || {}).merge(serialization_user)
|
15
17
|
serializer_class = "#{controller_name.singularize.camelize}Serializer".constantize
|
16
18
|
send("respond_for_#{action}", record, serializer_class, context)
|
17
19
|
rescue NoMethodError
|
@@ -42,7 +44,7 @@ module JsonapiResponses
|
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
45
|
-
def respond_for_destroy(record)
|
47
|
+
def respond_for_destroy(record, _, _)
|
46
48
|
if record.destroy
|
47
49
|
render json: { message: 'register destroyed successfully' }, status: :ok
|
48
50
|
else
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# JsonapiResponses folder
|
2
|
+
module JsonapiResponses
|
3
|
+
# Create a helper to intercept de current_user
|
4
|
+
module UserContextProvider
|
5
|
+
# Este método se incluirá en el controlador y será accesible en los serializadores
|
6
|
+
def serialization_user
|
7
|
+
{ current_user: current_user }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi_responses
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Ortega
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: My first gem which tries to get simplier the way you responde in your
|
14
14
|
API
|
@@ -27,12 +27,12 @@ files:
|
|
27
27
|
- Rakefile
|
28
28
|
- app/models/item.rb
|
29
29
|
- app/serializers/item_serializer.rb
|
30
|
-
- builds/jsonapi_responses-0.1.0.gem
|
31
30
|
- config/database.yml
|
32
31
|
- lib/jsonapi_responses.rb
|
33
32
|
- lib/jsonapi_responses/engine.rb
|
34
33
|
- lib/jsonapi_responses/respondable.rb
|
35
34
|
- lib/jsonapi_responses/serializable.rb
|
35
|
+
- lib/jsonapi_responses/user_context_provider.rb
|
36
36
|
- lib/jsonapi_responses/version.rb
|
37
37
|
homepage: https://www.oortega.dev/gems
|
38
38
|
licenses:
|
Binary file
|