Sha256: 99b48fd217dd5680b3af7a97ca5ea5ccfbbccf4f017d0411151879a1a39a9321

Contents?: true

Size: 750 Bytes

Versions: 1

Compression:

Stored size: 750 Bytes

Contents

# frozen_string_literal: true

module Micro::Struct
  module Features
    DISABLED =
      { to_ary: false,
        to_hash: false,
        to_proc: false,
        readonly: false,
        instance_copy: false }.freeze

    Check = ->(to_ary:, to_hash:, to_proc:, readonly:, instance_copy:) do
      { to_ary: to_ary,
        to_hash: to_hash,
        to_proc: to_proc,
        readonly: readonly,
        instance_copy: instance_copy }
    end

    Names = ->(values) do
      NormalizeNames::AsSymbols.(values, context: 'feature')
    end

    def self.require(values)
      to_enable = Names[values].each_with_object({}) { |name, memo| memo[name] = true }

      Check.(**DISABLED.merge(to_enable))
    end
  end

  private_constant :Features
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
u-struct-0.11.0 lib/micro/struct/features.rb