Sha256: 5a18ed07309ce10215ec760b8530488a70b5aa3af35c81e7cb999b627aec541a

Contents?: true

Size: 1.02 KB

Versions: 14

Compression:

Stored size: 1.02 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={})
        instance.load(string, collect_load_options(string, options))
      end

      def dump(object, options={})
        instance.dump(object, collect_dump_options(object, options))
      end

    protected

      def collect_load_options(string, options)
        collect_options :load_options, options, [ string, options ]
      end

      def collect_dump_options(object, options)
        collect_options :dump_options, options, [ object, options ]
      end

      def collect_options(method, overrides, args)
        global, local = *[MultiJson, self].map{ |r| r.send(method, *args) }
        local.merge(global).merge(overrides)
      end

    end
  end
end

Version data entries

14 entries across 14 versions & 5 rubygems

Version Path
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/multi_json-1.7.2/lib/multi_json/adapter.rb
vagrant-shell-0.2.6 vendor/bundle/gems/multi_json-1.7.2/lib/multi_json/adapter.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/multi_json-1.7.2/lib/multi_json/adapter.rb
challah-1.0.0.beta3 vendor/bundle/gems/multi_json-1.7.2/lib/multi_json/adapter.rb
vagrant-shell-0.2.5 vendor/bundle/gems/multi_json-1.7.2/lib/multi_json/adapter.rb
fc-webicons-0.0.4 vendor/bundle/ruby/1.9.1/gems/multi_json-1.7.2/lib/multi_json/adapter.rb
challah-1.0.0.beta2 vendor/bundle/gems/multi_json-1.7.2/lib/multi_json/adapter.rb
challah-1.0.0.beta vendor/bundle/gems/multi_json-1.7.2/lib/multi_json/adapter.rb
fc-webicons-0.0.3 vendor/bundle/ruby/1.9.1/gems/multi_json-1.7.2/lib/multi_json/adapter.rb
fc-webicons-0.0.2 vendor/bundle/ruby/1.9.1/gems/multi_json-1.7.2/lib/multi_json/adapter.rb
fc-webicons-0.0.1 vendor/bundle/ruby/1.9.1/gems/multi_json-1.7.2/lib/multi_json/adapter.rb
multi_json-1.7.2 lib/multi_json/adapter.rb
multi_json-1.7.1 lib/multi_json/adapter.rb
multi_json-1.7.0 lib/multi_json/adapter.rb