serialize_partials_attributes 0.0.2 → 1.0.0
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3f2a56e5413c46aefc155f9bf39e112afca6853
|
4
|
+
data.tar.gz: 67c94dfe103e1ae585f729590402d0b6dab2a024
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 465eb6ebd82f695ed8d5cc2e4b3f0f51ca68f589a8760e677b35e89e6d73b1ef028a62a47cae3ba2b1bd396dbfbaf0d0ec071b20884e6dfff99104dcebe7ffd2
|
7
|
+
data.tar.gz: 35b7e90687713d5802c860c67b611d0d3e7940b213c2f313d68330a4f0dd9c29053fb33f925e17b4489903de59b6f6022bbb8714ded9556171be29b531530132
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module SerializePartialsAttributes
|
2
|
+
class Configuration
|
3
|
+
@@field = "fields"
|
4
|
+
@@split_by = "+"
|
5
|
+
|
6
|
+
def self.field
|
7
|
+
@@field
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.field=(value)
|
11
|
+
@@field = value
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.split_by
|
15
|
+
@@split_by
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.split_by=(value)
|
19
|
+
@@split_by = value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SerializePartialsAttributes
|
2
|
+
module ControllerExtensions
|
3
|
+
def render *args, &block
|
4
|
+
args[0].merge!(attributes_to_serialize)
|
5
|
+
super
|
6
|
+
end
|
7
|
+
private
|
8
|
+
def attributes_to_serialize
|
9
|
+
{only_attributes: fields_params}
|
10
|
+
end
|
11
|
+
def fields_params
|
12
|
+
if params.has_key?(SerializePartialsAttributes::Configuration.field)
|
13
|
+
params[:fields].split(SerializePartialsAttributes::Configuration.split_by)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module SerializePartialsAttributes
|
2
|
+
module SerializerExtensions
|
3
|
+
def attributes(*args)
|
4
|
+
object = super
|
5
|
+
if has_only_attributes_key?
|
6
|
+
object.slice!(*only_attributes)
|
7
|
+
end
|
8
|
+
object
|
9
|
+
end
|
10
|
+
def has_only_attributes_key?
|
11
|
+
if self.instance_options.has_key?(:only_attributes) && self.instance_options[:only_attributes].present?
|
12
|
+
true
|
13
|
+
else
|
14
|
+
false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
def only_attributes
|
18
|
+
self.instance_options[:only_attributes].map { |x| x.to_sym }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,39 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
module Serializer
|
18
|
-
extend ActiveSupport::Concern
|
19
|
-
included do
|
20
|
-
def attributes(*args)
|
21
|
-
object = super
|
22
|
-
if has_only_attributes_key?
|
23
|
-
object.slice!(*only_attributes)
|
24
|
-
end
|
25
|
-
object
|
26
|
-
end
|
27
|
-
end
|
28
|
-
def has_only_attributes_key?
|
29
|
-
if self.instance_options.has_key?(:only_attributes) && self.instance_options[:only_attributes].present?
|
30
|
-
true
|
31
|
-
else
|
32
|
-
false
|
33
|
-
end
|
34
|
-
end
|
35
|
-
def only_attributes
|
36
|
-
self.instance_options[:only_attributes].map { |x| x.to_sym }
|
37
|
-
end
|
38
|
-
end
|
1
|
+
require "active_model_serializers"
|
2
|
+
require "serialize_partials_attributes/controller_extensions"
|
3
|
+
require "serialize_partials_attributes/serializer_extensions"
|
4
|
+
require "serialize_partials_attributes/configuration"
|
5
|
+
|
6
|
+
if defined?(ActionController::API)
|
7
|
+
ActionController::API.include SerializePartialsAttributes::ControllerExtensions
|
8
|
+
end
|
9
|
+
|
10
|
+
if defined?(ActiveModel::Serializer)
|
11
|
+
ActiveModel::Serializer.prepend SerializePartialsAttributes::SerializerExtensions
|
12
|
+
end
|
13
|
+
|
14
|
+
module SerializePartialsAttributes
|
15
|
+
|
39
16
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serialize_partials_attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thiago Soares de Melo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: thiago.soaresm19@gmail.com
|
@@ -17,6 +17,9 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- lib/serialize_partials_attributes.rb
|
20
|
+
- lib/serialize_partials_attributes/configuration.rb
|
21
|
+
- lib/serialize_partials_attributes/controller_extensions.rb
|
22
|
+
- lib/serialize_partials_attributes/serializer_extensions.rb
|
20
23
|
homepage: https://github.com/teago19/serialize_partials_attributes
|
21
24
|
licenses:
|
22
25
|
- MIT
|
@@ -40,5 +43,5 @@ rubyforge_project:
|
|
40
43
|
rubygems_version: 2.5.2.1
|
41
44
|
signing_key:
|
42
45
|
specification_version: 4
|
43
|
-
summary: Extention to ActiveModel::Serializer to select with attributes will be serialized
|
46
|
+
summary: Extention to ActiveModel::Serializer to select with attributes will be serialized
|
44
47
|
test_files: []
|