Sha256: d96767e8dc25990e069c67c7b18774c3cbf5ed072037bfc7a4b113e6ac2cbaa2

Contents?: true

Size: 1.21 KB

Versions: 11

Compression:

Stored size: 1.21 KB

Contents

module Dry::Initializer
  # Module-level DSL
  module DSL
    # Setting for null (undefined value)
    # @return [nil, Dry::Initializer::UNDEFINED]
    attr_reader :null

    # Returns a version of the module with custom settings
    # @option settings [Boolean] :undefined
    #   If unassigned params and options should be treated different from nil
    # @return [Dry::Initializer]
    def [](undefined: true, **)
      null = (undefined == false) ? nil : UNDEFINED
      Module.new.tap do |mod|
        mod.extend DSL
        mod.include self
        mod.send(:instance_variable_set, :@null, null)
      end
    end

    # Returns mixin module to be included to target class by hand
    # @return [Module]
    # @yield proc defining params and options
    def define(procedure = nil, &block)
      config = Config.new(null: null)
      config.instance_exec(&(procedure || block))
      config.mixin.include Mixin::Root
      config.mixin
    end

    private

    def extended(klass)
      config = Config.new(klass, null: null)
      klass.send :instance_variable_set, :@dry_initializer, config
      klass.include Mixin::Root
    end

    def self.extended(mod)
      mod.instance_variable_set :@null, UNDEFINED
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
dry-initializer-3.0.4 lib/dry/initializer/dsl.rb
dry-initializer-3.0.3 lib/dry/initializer/dsl.rb
dry-initializer-3.0.2 lib/dry/initializer/dsl.rb
dry-initializer-3.0.1 lib/dry/initializer/dsl.rb
dry-initializer-3.0.0 lib/dry/initializer/dsl.rb
dry-initializer-2.5.0 lib/dry/initializer/dsl.rb
dry-initializer-2.4.0 lib/dry/initializer/dsl.rb
dry-initializer-2.3.0 lib/dry/initializer/dsl.rb
dry-initializer-2.2.0 lib/dry/initializer/dsl.rb
dry-initializer-2.1.0 lib/dry/initializer/dsl.rb
dry-initializer-2.0.0 lib/dry/initializer/dsl.rb