Module: MultiJson Deprecated

Defined in:
lib/multi_json.rb

Overview

Deprecated.

Use MultiJSON (all-caps) instead. Will be removed in v2.0.

Backward-compatible alias for the legacy “MultiJson“ constant name

Downstream code that still writes “MultiJson.parse(…)“ or “rescue MultiJson::ParseError“ continues to work, but emits a one-time deprecation warning pointing at “MultiJSON“. The module forwards every method call to MultiJSON via MultiJson.method_missing and resolves constant access via MultiJson.const_missing, so both dotted calls and “::“ constant lookups (including rescue clauses) route through the canonical module.

Class Method Summary collapse

Class Method Details

.const_missing(name) ⇒ Object

Resolve missing constants to their MultiJSON counterparts

Enables “rescue MultiJson::ParseError“ and “MultiJson::Adapters::Oj“ to keep working during the deprecation cycle.

Examples:

MultiJson::ParseError  # returns MultiJSON::ParseError

Parameters:

  • name (Symbol)

    constant name

Returns:

  • (Object)

    the resolved constant from MultiJSON



332
333
334
335
336
# File 'lib/multi_json.rb', line 332

def const_missing(name)
  ::MultiJSON.warn_deprecation_once(:multi_json_constant,
    "The MultiJson constant is deprecated and will be removed in v2.0. Use MultiJSON instead.")
  ::MultiJSON.const_get(name)
end

.method_missing(name, *args, **kwargs, &block) ⇒ Object

Forward method calls to MultiJSON, emitting a one-time warning

Uses explicit “*args, **kwargs, &block“ forwarding because mutant’s AST structure table on the current parser version does not yet recognize “…“ forwarding nodes, so the module would crash mutation analysis. The rubocop exclusions below document that intent.

rubocop:disable Naming/BlockForwarding, Style/ArgumentsForwarding

Examples:

MultiJson.parse('{"a":1}')   # delegates to MultiJSON.parse

Returns:

  • (Object)

    the delegated call’s return value



298
299
300
301
302
303
304
305
306
# File 'lib/multi_json.rb', line 298

def method_missing(name, *args, **kwargs, &block)
  ::MultiJSON.warn_deprecation_once(:multi_json_constant,
    "The MultiJson constant is deprecated and will be removed in v2.0. Use MultiJSON instead.")
  if ::MultiJSON.respond_to?(name)
    ::MultiJSON.public_send(name, *args, **kwargs, &block)
  else
    super
  end
end

.respond_to_missing?(name, include_private) ⇒ Boolean

Respond to any method MultiJSON responds to

Examples:

MultiJson.respond_to?(:parse)  #=> true

Parameters:

  • name (Symbol)

    method name

  • include_private (Boolean)

    include private methods

Returns:

  • (Boolean)

    true if MultiJSON responds to the method



317
318
319
# File 'lib/multi_json.rb', line 317

def respond_to_missing?(name, include_private)
  ::MultiJSON.respond_to?(name, include_private)
end