Module: MadFlatter::Options

Extended by:
OptionsDefaultable, OptionsValidatable
Defined in:
lib/mad_flatter/options.rb

Overview

Defines methods to create options.

Constant Summary

Constants included from OptionsDefaultable

MadFlatter::OptionsDefaultable::DEFAULT_OPTIONS

Constants included from NamespaceOptionable

NamespaceOptionable::OPTION_NAMESPACE, NamespaceOptionable::OPTION_NAMESPACE_DEFAULT

Constants included from MetadataOptionable

MetadataOptionable::OPTION_METADATA, MetadataOptionable::OPTION_METADATA_DEFAULT, MetadataOptionable::OPTION_METADATA_EXCLUDE, MetadataOptionable::OPTION_METADATA_INCLUDE, MetadataOptionable::OPTION_METADATA_VALUES

Constants included from OptionsValidatable

MadFlatter::OptionsValidatable::OPTIONS

Class Method Summary collapse

Methods included from OptionsValidatable

validate_option_keys!, validate_option_metadata!, validate_option_namespace!, validate_options!, validate_options_type!

Class Method Details

.defaultObject



40
41
42
# File 'lib/mad_flatter/options.rb', line 40

def default
  with_defaults({})
end

.new(**options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mad_flatter/options.rb', line 14

def new(**options)
  immutable_struct_ex = ImmutableStructEx.new(**options) do
    def namespace?
      return false unless respond_to? :namespace

      namespace || false
    end

    def metadata?
      # This should never return false since
      # the :metadata option is required.
      return false unless respond_to? :metadata

       || false
    end
  end
  validate_options! options: immutable_struct_ex.to_h
  immutable_struct_ex
end

.with_defaults(options, defaults: DEFAULT_OPTIONS) ⇒ Object



34
35
36
37
38
# File 'lib/mad_flatter/options.rb', line 34

def with_defaults(options, defaults: DEFAULT_OPTIONS)
  validate_options_type!(options: options) unless options.respond_to? :to_h

  new(**defaults.to_h.merge(options.to_h))
end