Sha256: 43e29ae02d13656d32178918e0e929995968adb427c82e28418aaec126cfdac3

Contents?: true

Size: 683 Bytes

Versions: 2

Compression:

Stored size: 683 Bytes

Contents

module Dry::Initializer::Builders
  # @private
  class Signature
    def self.[](config)
      new(config).call
    end

    def call
      [*required_params, *optional_params, '*', options].compact.join(', ')
    end

    private

    def initialize(config)
      @config  = config
      @options = config.options.any?
      @null    = config.null ? 'Dry::Initializer::UNDEFINED' : 'nil'
    end

    def required_params
      @config.params.reject(&:optional).map(&:source)
    end

    def optional_params
      @config.params.select(&:optional).map { |rec| "#{rec.source} = #{@null}" }
    end

    def options
      '**__dry_initializer_options__' if @options
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dry-initializer-3.0.4 lib/dry/initializer/builders/signature.rb
dry-initializer-3.0.3 lib/dry/initializer/builders/signature.rb