class Dry::Configurable::DSL
Setting
DSL
used by the class API
@api private
Constants
- VALID_NAME
Attributes
ast[R]
@api private
compiler[R]
@api private
Public Class Methods
new(&block)
click to toggle source
@api private
# File lib/dry/configurable/dsl.rb, line 24 def initialize(&block) @compiler = Compiler.new @ast = [] instance_exec(&block) if block end
Public Instance Methods
setting(name, *args, &block)
click to toggle source
Register a new setting node and compile it into a setting object
@see ClassMethods.setting
@api public @return Setting
# File lib/dry/configurable/dsl.rb, line 35 def setting(name, *args, &block) unless VALID_NAME.match?(name.to_s) raise ArgumentError, "#{name} is not a valid setting name" end args = Args.new(args) args.ensure_valid_options default, opts = args node = [:setting, [name.to_sym, default, opts == default ? EMPTY_HASH : opts]] if block if block.arity.zero? ast << [:nested, [node, DSL.new(&block).ast]] else ast << [:constructor, [node, block]] end else ast << node end compiler.visit(ast.last) end