forest_liana 1.5.0 → 1.5.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: 370f07e1de98a6ce3327d97c481023c434f85b45
4
- data.tar.gz: bcb19bdd6901d1e41fea931f89d9da81c52ffdde
3
+ metadata.gz: 8c12d6ca66245644504b33629b1fed37aa2f490a
4
+ data.tar.gz: 474f0b4140dd86509ad7709e99cd7888cb2182ec
5
5
  SHA512:
6
- metadata.gz: 9e30e668b9116aaaa701bd0046747c33dac6cc22e806970af081a34b346f7bc6810a4df5ec4f50d4013d9dc6ec93af3d9bc9eefdbd97e5599e1c7829c7be8efe
7
- data.tar.gz: 0aa6c921a2fab719a0425b5fc8f75578c733c71a47c5e392de4ee69e12d32dea561f77eaf6516a7f7e4aa2742ece9aad82974f5114dd16b8f28f0af1d53130fe
6
+ metadata.gz: c1105cd520ac6d0feba4672c163900ca91f05214bef34a1373ee0fb84404ba1a038f358397d817b763816d4707cc99916a7a7cd271b18537ba4965aa09edb3f9
7
+ data.tar.gz: dca34559ad4e126ecd21167d4ca55712f12615742d1df42dd41263941209bce1f848698ce230d88ca43b62f4fb3194d3272c874358ad332b64bf6fb3de06cfb3
@@ -10,14 +10,15 @@ module ForestLiana
10
10
 
11
11
  wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
12
12
 
13
-
14
13
  def forest_user
15
14
  @jwt_decoded_token
16
15
  end
17
16
 
18
17
  def serialize_model(model, options = {})
19
18
  options[:is_collection] = false
20
- JSONAPI::Serializer.serialize(model, options)
19
+ json = JSONAPI::Serializer.serialize(model, options)
20
+
21
+ force_utf8_encoding(json)
21
22
  end
22
23
 
23
24
  def serialize_models(models, options = {})
@@ -34,7 +35,7 @@ module ForestLiana
34
35
  json[:meta][:has_more] = options[:has_more]
35
36
  end
36
37
 
37
- json
38
+ force_utf8_encoding(json)
38
39
  end
39
40
 
40
41
  def authenticate_user_from_jwt
@@ -53,5 +54,36 @@ module ForestLiana
53
54
  end
54
55
  end
55
56
 
57
+ private
58
+
59
+ def force_utf8_encoding(json)
60
+ if json['data'].class == Array
61
+ # NOTICE: Collection of records case
62
+ json['data'].each { |record| force_utf8_attributes_encoding(record) }
63
+ else
64
+ # NOTICE: Single record case
65
+ force_utf8_attributes_encoding(json['data'])
66
+ end
67
+
68
+ json['included'].each do |association|
69
+ force_utf8_attributes_encoding(association)
70
+ end
71
+
72
+ json
73
+ end
74
+
75
+ def force_utf8_attributes_encoding(model)
76
+ # NOTICE: Declare all strings are encoded in utf-8
77
+ model['attributes'].each do |name, value|
78
+ if value.respond_to?(:force_encoding)
79
+ begin
80
+ model['attributes'][name] = value.force_encoding('utf-8')
81
+ rescue
82
+ # NOTICE: Enums are frozen Strings
83
+ end
84
+ end
85
+ end
86
+ end
87
+
56
88
  end
57
89
  end
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "1.5.0"
2
+ VERSION = "1.5.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_liana
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Munda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-12 00:00:00.000000000 Z
11
+ date: 2016-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails