promethee 1.0.1 → 1.0.2

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: 0446ad6a008e7f126a6bd3e691f2d9fb1cdf1164
4
- data.tar.gz: faffb9120096340ab927218699794449beeb1b08
3
+ metadata.gz: ff47d2fab2501f64ec51b21f530d35a1132d1819
4
+ data.tar.gz: 3ec913a94a54255692cab5058afe015c5d3dd5d0
5
5
  SHA512:
6
- metadata.gz: f428c8ae156ddb16051a183f7b4e5b721891baa1b2cf1501bb219954d4b6e2756e794a9d60bf2d45a666ace2ccbe43956f32e7b2dadfa823271c575a06eb13d7
7
- data.tar.gz: fea5fa53d6f350df3666b5eb656ff0ffb75e5209227a663236a3038a4705a68968b6242463e9a410220466b68e3fa8c4f141e1b6ff7d1b4ac63bc9b9c1170793
6
+ metadata.gz: d372fe3fd96e76820fb167ddd1927ea91773162cde7abf3606db752eabbfcdae4a56ecfcf476a268a77752b6ca1464abd4c400479b83121ddf18f676c800b787
7
+ data.tar.gz: cdb2fdd8b69026dfb5673108f2a659e2a866b9f1efff49438bd4b04493f6787f0cdfe354082614d5181e505d8d7520d0bffcacbc74b55dcbf2f9924e3f54ac7c
@@ -1,5 +1,5 @@
1
1
  <%
2
- master_data ||= {}
2
+ master_data ||= nil
3
3
  promethee_data = Promethee::Data.new master_data
4
4
  %>
5
5
 
@@ -30,8 +30,27 @@ module Promethee
30
30
 
31
31
  protected
32
32
 
33
- def convert_if_necessary(string_or_hash)
34
- string_or_hash.is_a?(String) ? JSON.parse(string_or_hash, symbolize_names: true) : string_or_hash
33
+ def convert_if_necessary(string_or_hash_or_anything)
34
+ # string_or_hash_or_anything could be a string a hash or anything so we need to handle potential exception to keep this method safe
35
+ begin
36
+ converted = string_or_hash_or_anything.is_a?(String) ? JSON.parse(string_or_hash_or_anything, symbolize_names: true) : string_or_hash_or_anything
37
+ rescue
38
+ converted = {}
39
+ end
40
+
41
+ # The parsed json could be anything: "\"hey\"" => "hey", "[\"hey\"]" => ["hey"], "null" => nil, ...
42
+ converted = {} unless converted.is_a? Hash
43
+
44
+ # The data might not be a json string so the "symbolize_names" options wouldn't do anything on a ruby hash because JSON.parse wouldn't be called
45
+ converted.deep_symbolize_keys!
46
+
47
+ # The children array is required in order to make this class work
48
+ converted[:children] = [] unless converted[:children].is_a?(Array)
49
+
50
+ # The type is required in order to make this class work
51
+ converted[:type] = converted[:type].is_a?(String) || converted[:type].is_a?(Symbol) ? converted[:type].to_s : 'page'
52
+
53
+ converted
35
54
  end
36
55
 
37
56
  def deep_clone(hash)
@@ -1,5 +1,5 @@
1
1
  module Promethee
2
2
  module Rails
3
- VERSION = '1.0.1'
3
+ VERSION = '1.0.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: promethee
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julien Dargelos