Module: MultiJSON::Options Private

Included in:
MultiJSON, Adapter
Defined in:
lib/multi_json/options.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.

Mixin providing configurable parse/generate options

Supports static hashes or dynamic callables (procs/lambdas). Extended by both MultiJSON (global options) and Adapter classes.

Constant Summary collapse

EMPTY_OPTIONS =

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.

Steep needs an inline ‘#:` annotation here because `{}.freeze` would be inferred as `Hash[untyped, untyped]` and trip `UnannotatedEmptyCollection`. The annotation requires `Hash.new.freeze` (not the `{}.freeze` rubocop would prefer) because the `#:` cast only applies to method-call results.

Hash.new.freeze

Instance Method Summary collapse

Instance Method Details

#default_dump_optionsHash

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.

Deprecated.

Use #default_generate_options instead. Will be removed in v2.0.

Get default generate options

Returns:

  • (Hash)

    frozen empty hash



155
156
157
# File 'lib/multi_json/options.rb', line 155

def default_dump_options
  default_generate_options
end

#default_generate_optionsHash

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.

Get default generate options

Returns:

  • (Hash)

    frozen empty hash



81
82
83
# File 'lib/multi_json/options.rb', line 81

def default_generate_options
  Concurrency.synchronize(:default_options) { @default_generate_options ||= EMPTY_OPTIONS }
end

#default_load_optionsHash

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.

Deprecated.

Use #default_parse_options instead. Will be removed in v2.0.

Get default parse options

Returns:

  • (Hash)

    frozen empty hash



146
147
148
# File 'lib/multi_json/options.rb', line 146

def default_load_options
  default_parse_options
end

#default_parse_optionsHash

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.

Get default parse options

Returns:

  • (Hash)

    frozen empty hash



73
74
75
# File 'lib/multi_json/options.rb', line 73

def default_parse_options
  Concurrency.synchronize(:default_options) { @default_parse_options ||= EMPTY_OPTIONS }
end

#dump_options(*args) ⇒ Hash

Deprecated.

Use #generate_options instead. Will be removed in v2.0.

Get options for generate operations

Examples:

MultiJSON.dump_options  #=> {}

Parameters:

  • args (Array<Object>)

    forwarded to the callable, ignored otherwise

Returns:

  • (Hash)

    resolved options hash



135
136
137
138
139
# File 'lib/multi_json/options.rb', line 135

def dump_options(*args)
  MultiJSON.warn_deprecation_once(:dump_options,
    "MultiJSON.dump_options is deprecated and will be removed in v2.0. Use MultiJSON.generate_options instead.")
  generate_options(*args)
end

#dump_options=(options) ⇒ Hash, Proc

Deprecated.

Use #generate_options= instead. Will be removed in v2.0.

Set options for generate operations

Examples:

MultiJSON.dump_options = {pretty: true}

Parameters:

  • options (Hash, Proc)

    options hash or callable

Returns:

  • (Hash, Proc)

    the options



107
108
109
110
111
# File 'lib/multi_json/options.rb', line 107

def dump_options=(options)
  MultiJSON.warn_deprecation_once(:dump_options=,
    "MultiJSON.dump_options= is deprecated and will be removed in v2.0. Use MultiJSON.generate_options= instead.")
  self.generate_options = options
end

#generate_options(*args) ⇒ Hash

Get options for generate operations

Examples:

MultiJSON.generate_options  #=> {}

Parameters:

  • args (Array<Object>)

    forwarded to the callable, ignored otherwise

Returns:

  • (Hash)

    resolved options hash



65
66
67
# File 'lib/multi_json/options.rb', line 65

def generate_options(*args)
  resolve_options(@generate_options, *args) || default_generate_options
end

#generate_options=(options) ⇒ Hash, Proc

Set options for generate operations

Examples:

MultiJSON.generate_options = {pretty: true}

Parameters:

  • options (Hash, Proc)

    options hash or callable

Returns:

  • (Hash, Proc)

    the options



37
38
39
40
# File 'lib/multi_json/options.rb', line 37

def generate_options=(options)
  OptionsCache.reset
  @generate_options = options
end

#load_options(*args) ⇒ Hash

Deprecated.

Use #parse_options instead. Will be removed in v2.0.

Get options for parse operations

Examples:

MultiJSON.load_options  #=> {}

Parameters:

  • args (Array<Object>)

    forwarded to the callable, ignored otherwise

Returns:

  • (Hash)

    resolved options hash



121
122
123
124
125
# File 'lib/multi_json/options.rb', line 121

def load_options(*args)
  MultiJSON.warn_deprecation_once(:load_options,
    "MultiJSON.load_options is deprecated and will be removed in v2.0. Use MultiJSON.parse_options instead.")
  parse_options(*args)
end

#load_options=(options) ⇒ Hash, Proc

Deprecated.

Use #parse_options= instead. Will be removed in v2.0.

Set options for parse operations

Examples:

MultiJSON.load_options = {symbolize_keys: true}

Parameters:

  • options (Hash, Proc)

    options hash or callable

Returns:

  • (Hash, Proc)

    the options



93
94
95
96
97
# File 'lib/multi_json/options.rb', line 93

def load_options=(options)
  MultiJSON.warn_deprecation_once(:load_options=,
    "MultiJSON.load_options= is deprecated and will be removed in v2.0. Use MultiJSON.parse_options= instead.")
  self.parse_options = options
end

#parse_options(*args) ⇒ Hash

Get options for parse operations

When ‘@parse_options` is a callable (proc/lambda), it’s invoked with ‘args` as positional arguments — typically the merged options hash from `Adapter.merged_parse_options`. When it’s a plain hash, ‘args` is ignored.

Examples:

MultiJSON.parse_options  #=> {}

Parameters:

  • args (Array<Object>)

    forwarded to the callable, ignored otherwise

Returns:

  • (Hash)

    resolved options hash



54
55
56
# File 'lib/multi_json/options.rb', line 54

def parse_options(*args)
  resolve_options(@parse_options, *args) || default_parse_options
end

#parse_options=(options) ⇒ Hash, Proc

Set options for parse operations

Examples:

MultiJSON.parse_options = {symbolize_keys: true}

Parameters:

  • options (Hash, Proc)

    options hash or callable

Returns:

  • (Hash, Proc)

    the options



25
26
27
28
# File 'lib/multi_json/options.rb', line 25

def parse_options=(options)
  OptionsCache.reset
  @parse_options = options
end