Sha256: 563b020d29009389f52cdd7f0f4457f304dbf5f6b9a3bab5c3c2d95cd99a297c
Contents?: true
Size: 1.31 KB
Versions: 1
Compression:
Stored size: 1.31 KB
Contents
require 'singleton' require 'multi_json/options' module MultiJson class Adapter extend Options include Singleton class << self def defaults(action, value) metaclass = class << self; self; end metaclass.instance_eval do define_method("default_#{action}_options"){ value } end end def load(string, options={}) raise self::ParseError if blank?(string) instance.load(string, collect_load_options(options).clone) end def dump(object, options={}) instance.dump(object, collect_dump_options(options).clone) end protected def collect_load_options(options) cache('load', options){ collect_options(:load_options, options).merge(options) } end def collect_dump_options(options) cache('dump', options){ collect_options(:dump_options, options).merge(options) } end def collect_options(method, *args) global, local = *[MultiJson, self].map{ |r| r.send(method, *args) } local.merge(global) end def cache(method, options) cache_key = [self, options].map(&:hash).join + method MultiJson.cached_options[cache_key] ||= yield end private def blank?(input) input.nil? || /\A\s*\z/ === input end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
multi_json-1.8.0 | lib/multi_json/adapter.rb |