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- DATA_RESERVED_NAMES =
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.
Method names defined on ‘Data` (and its ancestors) that cannot be used as setting names because `Data.define` would reject them, which would break Config#to_data.
::Data.instance_methods.to_set.freeze
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.
21 22 23 24 25 26 |
# File 'lib/dry/configurable/dsl.rb', line 21 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.
17 18 19 |
# File 'lib/dry/configurable/dsl.rb', line 17 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.
15 16 17 |
# File 'lib/dry/configurable/dsl.rb', line 15 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.
19 20 21 |
# File 'lib/dry/configurable/dsl.rb', line 19 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.
59 60 61 |
# File 'lib/dry/configurable/dsl.rb', line 59 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.
63 64 65 |
# File 'lib/dry/configurable/dsl.rb', line 63 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
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/dry/configurable/dsl.rb', line 33 def setting(name, **, &block) unless VALID_NAME.match?(name.to_s) raise ArgumentError, "#{name} is not a valid setting name" end if DATA_RESERVED_NAMES.include?(name.to_sym) raise ArgumentError, "#{name.inspect} is not a valid setting name: it conflicts with a Data " \ "instance method, which would break Config#to_data" 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 |