Method: Graphiti::Util::Hash.split_json

Defined in:
lib/graphiti/util/hash.rb

.split_json(string) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/graphiti/util/hash.rb', line 66

def self.split_json(string)
  start, opens, closes, index = 0, 0, 0, -1
  [].tap do |jsons|
    string[0..string.length].each_char do |char|
      index += 1
      opens += 1 if char == "{"
      if char == "}"
        closes += 1

        if opens == closes
          jsons << string.slice(start..index)
          start = index + 2
        end
      end
    end
  end
end