Module: Mml::ContextOptions

Extended by:
ContextOptions
Included in:
ContextOptions
Defined in:
lib/mml/context_options.rb

Instance Method Summary collapse

Instance Method Details

#normalize_context_option(context:, register:, default_context:, warning_source:) ⇒ Object

Normalize the public ‘context:` / `register:` options into one context id.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mml/context_options.rb', line 8

def normalize_context_option(
  context:,
  register:,
  default_context:,
  warning_source:
)
  raise_if_conflicting_context_options!(context, register)

  if register
    return normalize_register_option(
      register,
      default_context,
      warning_source,
    )
  end

  return default_context unless context_specified?(context)

  normalize_context_reference(context) || default_context
end

#normalize_context_reference(reference) ⇒ Object

Collapse supported references to the symbol id MML uses internally.

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
38
# File 'lib/mml/context_options.rb', line 30

def normalize_context_reference(reference)
  return nil if reference.nil?
  return reference if reference.is_a?(Symbol)
  return reference.to_sym if reference.is_a?(String)
  return reference.id.to_sym if reference.respond_to?(:id)

  raise ArgumentError,
        "Unsupported context/register reference: #{reference.inspect}"
end

#warn_register_deprecation(source) ⇒ Object

Centralize the compatibility warning for parse/configuration callers.



41
42
43
# File 'lib/mml/context_options.rb', line 41

def warn_register_deprecation(source)
  warn "[Mml] `register` is deprecated in #{source}; use `context` instead."
end