Module: MultiJSON::AdapterSelector Private

Extended by:
AdapterSelector
Included in:
MultiJSON, AdapterSelector
Defined in:
lib/multi_json/adapter_selector.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Handles adapter discovery, loading, and selection

Adapters can be specified as:

  • Symbol/String: adapter name (e.g., :oj, “json_gem”)

  • Module: adapter class directly

  • nil/false: use default adapter

Constant Summary collapse

REQUIREMENT_MAP =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Backwards-compatible view of ADAPTERS that exposes only the require paths. Tests still poke at this constant to stub or break the require step.

ADAPTERS.transform_values { |meta| meta[:require] }.freeze

Instance Method Summary collapse

Instance Method Details

#default_adapterSymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the default adapter to use

Examples:

AdapterSelector.default_adapter  #=> :oj

Returns:

  • (Symbol)

    adapter name



61
62
63
# File 'lib/multi_json/adapter_selector.rb', line 61

def default_adapter
  Concurrency.synchronize(:default_adapter) { @default_adapter ||= detect_best_adapter }
end

#default_adapter_excluding(excluded) ⇒ Class

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the default adapter class, excluding the given adapter name

Used by adapters that only implement one direction (e.g. FastJsonparser only parses) so the other direction can be delegated to whichever library MultiJSON would otherwise pick.

Examples:

AdapterSelector.default_adapter_excluding(:fast_jsonparser)  #=> MultiJSON::Adapters::Oj

Parameters:

  • excluded (Symbol)

    adapter name to skip during detection

Returns:

  • (Class)

    the adapter class



76
77
78
79
80
81
82
83
# File 'lib/multi_json/adapter_selector.rb', line 76

def default_adapter_excluding(excluded)
  Concurrency.synchronize(:default_adapter) do
    name = loaded_adapter(excluding: excluded)
    name ||= installable_adapter(excluding: excluded)
    name ||= fallback_adapter
    load_adapter_by_name(name.to_s)
  end
end