lib/qonfig/dsl.rb in qonfig-0.1.0 vs lib/qonfig/dsl.rb in qonfig-0.2.0
- old
+ new
@@ -11,16 +11,17 @@
# @api private
# @since 0.1.0
def extended(child_klass)
child_klass.instance_variable_set(:@commands, Qonfig::CommandSet.new)
- class << child_klass
+ 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)
+ super
end
- end
+ end)
end
end
# @return [Qonfig::CommandSet]
#
@@ -28,34 +29,74 @@
# @since 0.1.0
def commands
@commands
end
- # @param key [String,Symbol]
+ # @param key [Symbol, String]
# @param initial_value [Object]
# @param nested_settings [Proc]
# @return [void]
#
+ # @see Qonfig::Commands::AddNestedOption
+ # @see Qonfig::Commands::AddOption
+ #
# @api public
# @since 0.1.0
def setting(key, initial_value = nil, &nested_settings)
- unless key.is_a?(Symbol) || key.is_a?(String)
- raise Qonfig::ArgumentError, 'Setting key should be a symbol or a string!'
- end
-
if block_given?
commands << Qonfig::Commands::AddNestedOption.new(key, nested_settings)
else
commands << Qonfig::Commands::AddOption.new(key, initial_value)
end
end
# @param data_set_klass [Class{Qonfig::DataSet}]
# @return [void]
#
+ # @see Qonfig::Comamnds::Compose
+ #
# @api private
# @sine 0.1.0
def compose(data_set_klass)
commands << Qonfig::Commands::Compose.new(data_set_klass)
+ end
+
+ # @param file_path [String]
+ # @option strict [Boolean]
+ # @return [void]
+ #
+ # @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)
+ end
+
+ # @return [void]
+ #
+ # @see Qonfig::Commands::LoadFromSelf
+ #
+ # @api public
+ # @since 0.2.0
+ def load_from_self
+ caller_location = caller(1, 1).first
+ commands << Qonfig::Commands::LoadFromSelf.new(caller_location)
+ end
+
+ # @option convert_values [Boolean]
+ # @option prefix [NilClass, String, Regexp]
+ # @return [void]
+ #
+ # @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(
+ convert_values: convert_values,
+ prefix: prefix,
+ trim_prefix: trim_prefix
+ )
end
end
end