Class: Dry::Configurable::DSL Private
- Inherits:
-
Object
- Object
- Dry::Configurable::DSL
- 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
- #ast ⇒ Object readonly private
- #compiler ⇒ Object readonly private
- #options ⇒ Object readonly private
Instance Method Summary collapse
- #config_class ⇒ Object private
- #default ⇒ Object private
-
#initialize(**options, &block) ⇒ DSL
constructor
private
A new instance of DSL.
-
#setting(name, **options, &block) ⇒ Object
private
Registers a new setting node and compile it into a setting object.
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(**, &block) @compiler = Compiler.new @ast = [] @options = instance_exec(&block) if block end |
Instance Attribute Details
#ast ⇒ Object (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 |
#compiler ⇒ Object (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 |
#options ⇒ Object (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 end |
Instance Method Details
#config_class ⇒ 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.
49 50 51 |
# File 'lib/dry/configurable/dsl.rb', line 49 def config_class [:config_class] end |
#default ⇒ 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.
53 54 55 |
# File 'lib/dry/configurable/dsl.rb', line 53 def default [: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
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, **, &block) unless VALID_NAME.match?(name.to_s) raise ArgumentError, "#{name} is not a valid setting name" end () = {default: default, config_class: config_class, **} node = [:setting, [name.to_sym, ]] if block ast << [:nested, [node, DSL.new(**@options, &block).ast]] else ast << node end compiler.visit(ast.last) end |