jsonapi-params 0.1.0 → 0.1.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 +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/jsonapi-params/param.rb +15 -5
- data/lib/jsonapi-params/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92819e75d15e69fa8dcd009b18abce677dc7be0c
|
4
|
+
data.tar.gz: bbe111be0cc21b32c77a24e79a9910cba212cf48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c48709bde4a2244475ddd033c4a098ee5d88599750e4ae7e60822ae9fc5060eca91f6e551b05c7abdd5b23ddafef5f928aa801489b7fd32441122d8860f6c01
|
7
|
+
data.tar.gz: 6d5b048a3b90cd016ee27fe3028273217711e91fdf4673bcf6c66a5fc95cdf427bc5bfed853fdb11d15e4220d17fe488c8690613e5c4ad0790b20718a02475f0
|
data/CHANGELOG.md
ADDED
data/lib/jsonapi-params/param.rb
CHANGED
@@ -31,9 +31,12 @@ module JSONAPI
|
|
31
31
|
#
|
32
32
|
# @param name [Array<Symbol>] Names of relationships
|
33
33
|
# @return [nil]
|
34
|
-
def belongs_to(
|
34
|
+
def belongs_to(relationship_name)
|
35
|
+
relationship_name = relationship_name.to_s
|
36
|
+
|
35
37
|
@whitelist_relationships ||= []
|
36
|
-
@whitelist_relationships <<
|
38
|
+
@whitelist_relationships << relationship_name.dasherize
|
39
|
+
@whitelist_relationships << relationship_name.underscore unless @whitelist_relationships.include?(relationship_name.underscore)
|
37
40
|
end
|
38
41
|
|
39
42
|
private
|
@@ -45,8 +48,11 @@ module JSONAPI
|
|
45
48
|
# @!scope class
|
46
49
|
# @!visibility private
|
47
50
|
def add_param(name)
|
51
|
+
name = name.to_s
|
52
|
+
|
48
53
|
@whitelist_attributes ||= []
|
49
|
-
@whitelist_attributes << name.
|
54
|
+
@whitelist_attributes << name.dasherize
|
55
|
+
@whitelist_attributes << name.underscore unless @whitelist_attributes.include?(name.underscore)
|
50
56
|
end
|
51
57
|
end
|
52
58
|
|
@@ -76,7 +82,11 @@ module JSONAPI
|
|
76
82
|
attributes = @data['attributes'] || {}
|
77
83
|
attributes = attributes.slice(*self.class.whitelist_attributes)
|
78
84
|
attributes = attributes.merge(relationships)
|
79
|
-
|
85
|
+
|
86
|
+
attributes.inject({}) do |attributes, (key, value)|
|
87
|
+
attributes[key.to_s.underscore.to_sym] = value
|
88
|
+
attributes
|
89
|
+
end
|
80
90
|
end
|
81
91
|
|
82
92
|
# Handles parameters to return relationships
|
@@ -95,7 +105,7 @@ module JSONAPI
|
|
95
105
|
elsif data.is_a?(Hash)
|
96
106
|
params = params_klass(relationship_key).new(relationship_object)
|
97
107
|
|
98
|
-
relationships["#{relationship_key}_id"] = params.id
|
108
|
+
relationships["#{relationship_key}_id".to_sym] = params.id
|
99
109
|
end
|
100
110
|
|
101
111
|
relationships
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noverde Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- ".gitignore"
|
91
91
|
- ".rspec"
|
92
92
|
- ".travis.yml"
|
93
|
+
- CHANGELOG.md
|
93
94
|
- Gemfile
|
94
95
|
- README.md
|
95
96
|
- Rakefile
|