Sha256: 4258d5cf16e859889da17ec798639cbee19f30361afe5538f4e97ef7c6b64d34

Contents?: true

Size: 638 Bytes

Versions: 1

Compression:

Stored size: 638 Bytes

Contents

# frozen_string_literal: true

module Micro::Struct
  class Factory
    require_relative 'factory/create_struct'

    def initialize(features)
      @features = Features.require(features)
    end

    NormalizeMemberNames = ->(values) do
      NormalizeNames::AsSymbols.(values, context: 'member')
    end

    def new(*members, required: nil, optional: nil, &block)
      optional_members = NormalizeMemberNames[optional]
      required_members = NormalizeMemberNames[members] + NormalizeMemberNames[required]

      CreateStruct.with(required_members, optional_members, @features, &block)
    end
  end

  private_constant :Factory
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
u-struct-0.10.0 lib/micro/struct/factory.rb