Returns :yajl|:json|:active|:none (an identifier for the current backend)
# File lib/rufus/json.rb, line 99 def self.backend ] yajl json active none ].find { |b| Rufus::Json.const_get(b.upcase) == @backend }.to_sym end
Forces a decoder JSON/ACTIVE_SUPPORT or any lambda pair that knows how to deal with JSON.
It's OK to pass a symbol as well, :yajl, :json, :active (or :none).
# File lib/rufus/json.rb, line 111 def self.backend= (b) if b.is_a?(Symbol) b = { :yajl => YAJL, :json => JSON, :active => ACTIVE, :none => NONE }[b] end @backend = b end
Decodes the given JSON string.
# File lib/rufus/json.rb, line 143 def self.decode (s) @backend[1].call(s) rescue @backend[2].call => e raise ParserError.new(e.message) end
Let's ActiveSupport do the E number notation.
# File lib/rufus/json.rb, line 164 def self.decode_e (s) s.match(E_REGEX) ? eval(s) : false end
[Re-]Attempts to detect a JSON backend
# File lib/rufus/json.rb, line 74 def self.detect_backend @backend = if defined?(::Yajl) YAJL elsif defined?(::JSON) JSON elsif defined?(ActiveSupport::JSON) ACTIVE_SUPPORT else NONE end end
Duplicates an object by turning it into JSON and back.
Don't laugh, yajl-ruby makes that faster than a Marshal copy.
# File lib/rufus/json.rb, line 155 def self.dup (o) (@backend == NONE) ? Marshal.load(Marshal.dump(o)) : decode(encode(o)) end
Encodes the given object to a JSON string.
# File lib/rufus/json.rb, line 122 def self.encode (o, opts={}) @backend[0].call(o, opts) end
Returns true if there is a backend set for parsing/encoding JSON
# File lib/rufus/json.rb, line 92 def self.has_backend? (@backend != NONE) end
Generated with the Darkfish Rdoc Generator 2.