Sha256: 6cd125dba0f4aa8a0c01b9f08fb047c56935beca452989dd0e86b83bde4b0c98

Contents?: true

Size: 991 Bytes

Versions: 84

Compression:

Stored size: 991 Bytes

Contents

module MultiJson
  module Options

    def load_options=(options)
      MultiJson.reset_cached_options!
      @load_options = options
    end

    def dump_options=(options)
      MultiJson.reset_cached_options!
      @dump_options = options
    end

    def load_options(*args)
      get_options :load_options, *args
    end

    def dump_options(*args)
      get_options :dump_options, *args
    end

    def default_load_options
      @default_load_options ||= {}
    end

    def default_dump_options
      @default_dump_options ||= {}
    end

    private

    def get_options(ivar, *args)
      defaults = send("default_#{ivar}")

      return defaults unless instance_variable_defined?("@#{ivar}")

      value = instance_variable_get("@#{ivar}")

      if value.respond_to?(:call) and value.arity
        value.arity == 0 ? value[] : value[*args]
      elsif Hash === value or value.respond_to?(:to_hash)
        value.to_hash
      else
        defaults
      end
    end
  end
end

Version data entries

84 entries across 83 versions & 7 rubygems

Version Path
scout-5.9.13 vendor/multi_json/lib/multi_json/options.rb
scout-5.9.12 vendor/multi_json/lib/multi_json/options.rb
scout-5.9.11 vendor/multi_json/lib/multi_json/options.rb
scout-5.9.10.pre vendor/multi_json/lib/multi_json/options.rb
scout-5.9.8 vendor/multi_json/lib/multi_json/options.rb
scout-5.9.7.2.pre vendor/multi_json/lib/multi_json/options.rb
scout-5.9.8.pre vendor/multi_json/lib/multi_json/options.rb
scout-5.9.7.1 vendor/multi_json/lib/multi_json/options.rb
scout-5.9.7.pre vendor/multi_json/lib/multi_json/options.rb
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/gems/multi_json-1.7.9/lib/multi_json/options.rb
scout-5.9.5 vendor/multi_json/lib/multi_json/options.rb
scout-5.9.4 vendor/multi_json/lib/multi_json/options.rb
scout-5.9.4.pre vendor/multi_json/lib/multi_json/options.rb
scout-5.9.3 vendor/multi_json/lib/multi_json/options.rb
multi_json-1.9.3 lib/multi_json/options.rb
scout-5.9.2 vendor/multi_json/lib/multi_json/options.rb
scout-5.9.1 vendor/multi_json/lib/multi_json/options.rb
scout-5.9.1.pre vendor/multi_json/lib/multi_json/options.rb
multi_json-1.9.2 lib/multi_json/options.rb
multi_json-1.9.1 lib/multi_json/options.rb