Class: Dry::Configurable::DSL Private

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/configurable/dsl.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Setting DSL used by the class API

Constant Summary collapse

VALID_NAME =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/\A[a-z_]\w*\z/i

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options, &block) ⇒ DSL

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of DSL.



17
18
19
20
21
22
# File 'lib/dry/configurable/dsl.rb', line 17

def initialize(**options, &block)
  @compiler = Compiler.new
  @ast = []
  @options = options
  instance_exec(&block) if block
end

Instance Attribute Details

#astObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



13
14
15
# File 'lib/dry/configurable/dsl.rb', line 13

def ast
  @ast
end

#compilerObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
# File 'lib/dry/configurable/dsl.rb', line 11

def compiler
  @compiler
end

#optionsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



15
16
17
# File 'lib/dry/configurable/dsl.rb', line 15

def options
  @options
end

Instance Method Details

#config_classObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



49
50
51
# File 'lib/dry/configurable/dsl.rb', line 49

def config_class
  options[:config_class]
end

#defaultObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
# File 'lib/dry/configurable/dsl.rb', line 53

def default
  options[:default_undefined] ? Undefined : nil
end

#setting(name, **options, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Registers a new setting node and compile it into a setting object

Returns:

  • Setting

See Also:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dry/configurable/dsl.rb', line 29

def setting(name, **options, &block)
  unless VALID_NAME.match?(name.to_s)
    raise ArgumentError, "#{name} is not a valid setting name"
  end

  ensure_valid_options(options)

  options = {default: default, config_class: config_class, **options}

  node = [:setting, [name.to_sym, options]]

  if block
    ast << [:nested, [node, DSL.new(**@options, &block).ast]]
  else
    ast << node
  end

  compiler.visit(ast.last)
end