module Lockme::JsonUtils

Mixin providing JSON encoding method compatible with LockMe API

Public Instance Methods

to_json() click to toggle source
# File lib/lockme/json_utils.rb, line 7
def to_json
  utf_str = @data.to_h.to_json.force_encoding('UTF-8')
  utf_str.each_codepoint.reduce(+'') do |str, codepoint|
    str << if codepoint > 127
             '\u' + codepoint.to_s(16).rjust(4, '0')
           else
             codepoint.chr
           end
  end
end