Sha256: 4e89bff372151548104795e1fcf4a85eedfb7a78492a8fc4473093dd89c0b09c

Contents?: true

Size: 683 Bytes

Versions: 9

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

9 entries across 9 versions & 1 rubygems

Version Path
dry-initializer-3.0.2 lib/dry/initializer/builders/signature.rb
dry-initializer-3.0.1 lib/dry/initializer/builders/signature.rb
dry-initializer-3.0.0 lib/dry/initializer/builders/signature.rb
dry-initializer-2.5.0 lib/dry/initializer/builders/signature.rb
dry-initializer-2.4.0 lib/dry/initializer/builders/signature.rb
dry-initializer-2.3.0 lib/dry/initializer/builders/signature.rb
dry-initializer-2.2.0 lib/dry/initializer/builders/signature.rb
dry-initializer-2.1.0 lib/dry/initializer/builders/signature.rb
dry-initializer-2.0.0 lib/dry/initializer/builders/signature.rb