Sha256: 5eebb3b66630a8232893ab10524e3b7dead52104a35e889f4822f68b3bb08460
Contents?: true
Size: 976 Bytes
Versions: 11
Compression:
Stored size: 976 Bytes
Contents
# Allows a Ruby String to be used to pass native Javascript objects/functions # when calling JSON#generate with a Rollbar::JSON::JsOptionsState instance. # # Example: # JSON.generate( # { foo: Rollbar::JSON::Value.new('function(){ alert("bar") }') }, # Rollbar::JSON::JsOptionsState.new # ) # # => '{"foo":function(){ alert(\"bar\") }}' # # MUST use the Ruby JSON encoder, as in the example. The ActiveSupport encoder, # which is installed with Rails, is invoked when calling Hash#to_json and #as_json, # and will not work. # module Rollbar module JSON class JsOptionsState < ::JSON::State; end class Value # :nodoc: attr_accessor :value def initialize(value) @value = value end def to_json(opts = {}) # Return the raw value if this is from the js middleware return value if opts.class == Rollbar::JSON::JsOptionsState # Otherwise convert to a string %Q["#{value}"] end end end end
Version data entries
11 entries across 11 versions & 1 rubygems