Sha256: 09ef09f082b70a1ae1b3518e98041cbcd653f4c70d7cff2b465496a1ec9a2b68

Contents?: true

Size: 933 Bytes

Versions: 2

Compression:

Stored size: 933 Bytes

Contents

# frozen_string_literal: true

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

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

    class << self
      def new(**options)
        immutable_struct_ex = ImmutableStructEx.new(**options) do
          def merge?
            fields == OPTION_FIELDS_MERGE
          end

          def strict?
            fields == OPTION_FIELDS_STRICT
          end

          def namespace?
            namespace || false
          end
        end
        validate_options! options: immutable_struct_ex.to_h
        immutable_struct_ex
      end

      def with_defaults(options, defaults: DEFAULT_OPTIONS)
        new(**defaults.to_h.merge(options.to_h))
      end

      def default
        with_defaults({})
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
deco_lite-0.1.1 lib/deco_lite/options.rb
deco_lite-0.1.0 lib/deco_lite/options.rb