lib/qonfig/dsl.rb in qonfig-0.16.0 vs lib/qonfig/dsl.rb in qonfig-0.17.0

- old
+ new

@@ -8,30 +8,42 @@ # @return [void] # # @api private # @since 0.1.0 def extended(child_klass) - child_klass.instance_variable_set(:@commands, Qonfig::CommandSet.new) + child_klass.instance_variable_set(:@definition_commands, Qonfig::CommandSet.new) + child_klass.instance_variable_set(:@instance_commands, Qonfig::CommandSet.new) child_klass.singleton_class.prepend(Module.new do def inherited(child_klass) - child_klass.instance_variable_set(:@commands, Qonfig::CommandSet.new) - child_klass.commands.concat(commands) + child_klass.instance_variable_set(:@definition_commands, Qonfig::CommandSet.new) + child_klass.instance_variable_set(:@instance_commands, Qonfig::CommandSet.new) + + child_klass.definition_commands.concat(definition_commands) + child_klass.instance_commands.concat(instance_commands) super end end) end end # @return [Qonfig::CommandSet] # # @api private - # @since 0.1.0 - def commands - @commands + # @since 0.17.0 + def definition_commands + @definition_commands end + # @return [Qonfig::CommandSet] + # + # @api private + # @since 0.17.0 + def instance_commands + @instance_commands + end + # @param key [Symbol, String] # @param initial_value [Object] # @param nested_settings [Proc] # @return [void] # @@ -40,13 +52,13 @@ # # @api public # @since 0.1.0 def setting(key, initial_value = nil, &nested_settings) if block_given? - commands << Qonfig::Commands::AddNestedOption.new(key, nested_settings) + definition_commands << Qonfig::Commands::Definition::AddNestedOption.new(key, nested_settings) else - commands << Qonfig::Commands::AddOption.new(key, initial_value) + definition_commands << Qonfig::Commands::Definition::AddOption.new(key, initial_value) end end # @param data_set_klass [Class<Qonfig::DataSet>] # @return [void] @@ -54,11 +66,11 @@ # @see Qonfig::Comamnds::Compose # # @api private # @sine 0.1.0 def compose(data_set_klass) - commands << Qonfig::Commands::Compose.new(data_set_klass) + definition_commands << Qonfig::Commands::Definition::Compose.new(data_set_klass) end # @param file_path [String] # @option strict [Boolean] # @return [void] @@ -66,22 +78,27 @@ # @see Qonfig::Commands::LoadFromYAML # # @api public # @since 0.2.0 def load_from_yaml(file_path, strict: true) - commands << Qonfig::Commands::LoadFromYAML.new(file_path, strict: strict) + definition_commands << Qonfig::Commands::Definition::LoadFromYAML.new( + file_path, strict: strict + ) end # @return [void] # # @see Qonfig::Commands::LoadFromSelf # # @api public # @since 0.2.0 def load_from_self(format: :yaml) caller_location = caller(1, 1).first - commands << Qonfig::Commands::LoadFromSelf.new(caller_location, format: format) + + definition_commands << Qonfig::Commands::Definition::LoadFromSelf.new( + caller_location, format: format + ) end # @option convert_values [Boolean] # @option prefix [NilClass, String, Regexp] # @return [void] @@ -89,11 +106,11 @@ # @see Qonfig::Commands::LoadFromENV # # @api public # @since 0.2.0 def load_from_env(convert_values: false, prefix: nil, trim_prefix: false) - commands << Qonfig::Commands::LoadFromENV.new( + definition_commands << Qonfig::Commands::Definition::LoadFromENV.new( convert_values: convert_values, prefix: prefix, trim_prefix: trim_prefix ) end @@ -103,11 +120,11 @@ # @return [void] # # @api public # @since 0.5.0 def load_from_json(file_path, strict: true) - commands << Qonfig::Commands::LoadFromJSON.new(file_path, strict: strict) + definition_commands << Qonfig::Commands::Definition::LoadFromJSON.new(file_path, strict: strict) end # @param file_path [String] # @option strict [Boolean] # @option via [Symbol] @@ -115,11 +132,13 @@ # @return [void] # # @api public # @since 0.7.0 def expose_yaml(file_path, strict: true, via:, env:) - commands << Qonfig::Commands::ExposeYAML.new(file_path, strict: strict, via: via, env: env) + definition_commands << Qonfig::Commands::Definition::ExposeYAML.new( + file_path, strict: strict, via: via, env: env + ) end # @param file_path [String] # @option strict [Boolean] # @option via [Symbol] @@ -127,11 +146,13 @@ # @return [void] # # @api public # @since 0.14.0 def expose_json(file_path, strict: true, via:, env:) - commands << Qonfig::Commands::ExposeJSON.new(file_path, strict: strict, via: via, env: env) + definition_commands << Qonfig::Commands::Definition::ExposeJSON.new( + file_path, strict: strict, via: via, env: env + ) end # @option env [Symbol, String] # @return [void] # @@ -139,8 +160,27 @@ # # @api public # @since 0.14.0 def expose_self(env:, format: :yaml) caller_location = caller(1, 1).first - commands << Qonfig::Commands::ExposeSelf.new(caller_location, env: env, format: format) + + definition_commands << Qonfig::Commands::Definition::ExposeSelf.new( + caller_location, env: env, format: format + ) + end + + # @param file_path [String] + # @option format [String, Symbol] + # @option strict [Boolean] + # @option expose [NilClass, String, Symbol] Environment key + # @return [void] + # + # @api public + # @since 0.17.0 + def values_file(file_path, format: :dynamic, strict: false, expose: nil) + caller_location = caller(1, 1).first + + instance_commands << Qonfig::Commands::Instantiation::ValuesFile.new( + file_path, caller_location, format: format, strict: strict, expose: expose + ) end end