jsonapi-params 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: e5a249c1dc7ab63566967bc11cfda5a9cadcf9c3
4
- data.tar.gz: 227888eacf0c5c0f538451b031d1344d63b42a5a
3
+ metadata.gz: 92819e75d15e69fa8dcd009b18abce677dc7be0c
4
+ data.tar.gz: bbe111be0cc21b32c77a24e79a9910cba212cf48
5
5
  SHA512:
6
- metadata.gz: d07526167def4f51cf4f7cfaa8e854028e95891d66a1c41f6a81ba205ac71cf672b3fccc015f930865a70ef0a127e4120fa45b8960358a2cf790559a5ef45d4e
7
- data.tar.gz: 772e64b470a3ff2f43da7724ace3898123b3b9033ca9e54447d0907643415d91af1e1a9cf0ae873b086b61e5b4847290774ff7d32d13b69c554ca7907677a827
6
+ metadata.gz: 7c48709bde4a2244475ddd033c4a098ee5d88599750e4ae7e60822ae9fc5060eca91f6e551b05c7abdd5b23ddafef5f928aa801489b7fd32441122d8860f6c01
7
+ data.tar.gz: 6d5b048a3b90cd016ee27fe3028273217711e91fdf4673bcf6c66a5fc95cdf427bc5bfed853fdb11d15e4220d17fe488c8690613e5c4ad0790b20718a02475f0
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # CHANGELOG
2
+
3
+ ## 0.1.1
4
+
5
+ * Change attributes and relationships to allow underscore and dasherize values
6
+
7
+ ## 0.1.0
8
+
9
+ * Initial version with attributes and relationships
@@ -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(relationship_names)
34
+ def belongs_to(relationship_name)
35
+ relationship_name = relationship_name.to_s
36
+
35
37
  @whitelist_relationships ||= []
36
- @whitelist_relationships << relationship_names.to_s.dasherize
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.to_s.dasherize
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
- attributes
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
@@ -1,5 +1,5 @@
1
1
  module JSONAPI
2
2
  module Param
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
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.0
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-26 00:00:00.000000000 Z
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