serialize_partials_attributes 0.0.1
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 +7 -0
- data/lib/serialize_partials_attributes.rb +39 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a5ba12e8b2712137fa3656eb0bbc2ee87394c3df
|
4
|
+
data.tar.gz: a3d0b33c042bf39b23a86e7e7525674e807f2a4a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a5df48f01c8136a99c81d53b68ed52c3a030346a6af1d28d3c36d82c5c2f1de70f7f1d785c045c9232c58d2530a19bfdbd27b131942b2b14552d8eea58867c51
|
7
|
+
data.tar.gz: 538a34a83af1afb3db8af5a63534a5d33a9fe335bdc4bab96ebd75f049bb90f3097e692d00f74b49446bd1d8d86e6a20f3d0156d8d5fcd05a3749c7acff2ec36
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module SerializePartialAttributes
|
2
|
+
module Controller
|
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?("fields")
|
13
|
+
params[:fields].split("+")
|
14
|
+
end
|
15
|
+
end
|
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
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: serialize_partials_attributes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Thiago Soares de Melo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: thiago.soaresm19@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/serialize_partials_attributes.rb
|
20
|
+
homepage: https://github.com/teago19/serialize_partials_attributes
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.5.2.1
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Extention to ActiveModel::Serializer to select with attributes will be serialized}
|
44
|
+
test_files: []
|