Sha256: 940023e80243eebcc1d7128d5362ea4ea7ad99046648bbabf626679ecc435677

Contents?: true

Size: 576 Bytes

Versions: 2

Compression:

Stored size: 576 Bytes

Contents

# frozen_string_literal: true

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

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

    def new(*required_members, required: nil, optional: nil, &struct_block)
      members = Members.new(required_members, required, optional)

      CreateStruct.with(members, struct_block, @features)
    end

    def instance(**members, &block)
      new(*members.keys, &block).new(**members)
    end
  end

  private_constant :Factory
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
u-struct-1.0.0 lib/micro/struct/factory.rb
u-struct-0.12.0 lib/micro/struct/factory.rb