class Dry::Configurable::DSL
Setting
DSL
used by the class API
@api private
Constants
- VALID_NAME
Attributes
ast[R]
compiler[R]
options[R]
Public Class Methods
new(**options, &block)
click to toggle source
# File lib/dry/configurable/dsl.rb, line 17 def initialize(**options, &block) @compiler = Compiler.new @ast = [] @options = options instance_exec(&block) if block end
Public Instance Methods
config_class()
click to toggle source
# File lib/dry/configurable/dsl.rb, line 49 def config_class options[:config_class] end
default()
click to toggle source
# File lib/dry/configurable/dsl.rb, line 53 def default options[:default_undefined] ? Undefined : nil end
setting(name, **options, &block)
click to toggle source
Registers a new setting node and compile it into a setting object
@see ClassMethods.setting
@api private @return Setting
# 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
Private Instance Methods
ensure_valid_options(options)
click to toggle source
# File lib/dry/configurable/dsl.rb, line 59 def ensure_valid_options(options) return if options.none? invalid_keys = options.keys - Setting::OPTIONS raise ArgumentError, "Invalid options: #{invalid_keys.inspect}" unless invalid_keys.empty? end
valid_and_invalid_options(options)
click to toggle source
Returns a tuple of valid and invalid options hashes derived from the options hash given to the setting
# File lib/dry/configurable/dsl.rb, line 69 def valid_and_invalid_options(options) options.partition { |k, _| Setting::OPTIONS.include?(k) }.map(&:to_h) end