Sha256: 6536518d0d81e6df1e9ace1b73a9df8aec40d5ae02a2ec9a6ddfd718f161e70b

Contents?: true

Size: 1.12 KB

Versions: 11

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require 'immutable_struct_ex'
require_relative 'options_defaultable'
require_relative 'options_validatable'

module MadFlatter
  # Defines methods to create options.
  module Options
    extend MadFlatter::OptionsDefaultable
    extend MadFlatter::OptionsValidatable

    class << self
      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

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

      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

      def default
        with_defaults({})
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
mad_flatter-3.0.8 lib/mad_flatter/options.rb
mad_flatter-3.0.7 lib/mad_flatter/options.rb
mad_flatter-3.0.6 lib/mad_flatter/options.rb
mad_flatter-3.0.5 lib/mad_flatter/options.rb
mad_flatter-3.0.4 lib/mad_flatter/options.rb
mad_flatter-3.0.3 lib/mad_flatter/options.rb
mad_flatter-3.0.2 lib/mad_flatter/options.rb
mad_flatter-3.0.1 lib/mad_flatter/options.rb
mad_flatter-3.0.0 lib/mad_flatter/options.rb
mad_flatter-2.1.0 lib/mad_flatter/options.rb
mad_flatter-2.0.0 lib/mad_flatter/options.rb