lib/qonfig/data_set.rb in qonfig-0.18.1 vs lib/qonfig/data_set.rb in qonfig-0.19.0

- old
+ new

@@ -24,10 +24,22 @@ raise(Qonfig::ArgumentError, 'Base class should be a type of Qonfig::DataSet') end Class.new(base_dataset_klass, &config_klass_definitions).new end + + # @param configurations [Hash<Symbol|String,Any>] + # @return [Boolean] + # + # @api public + # @since 0.19.0 + def valid_with?(configurations = {}) + new(configurations) + true + rescue Qonfig::ValidationError + false + end end # @return [Qonfig::Settings] # # @api public @@ -300,10 +312,30 @@ # @since 0.13.0 def valid? thread_safe_access { validator.valid? } end + # @param configurations [Hash<String,Symbol|Any>] + # @return [Boolean] + # + # @api public + # @since 0.19.0 + def valid_with?(configurations = {}) + # NOTE: + # 'dup.configure(configurations)' has better thread-safety than 'with(configurations)' + # pros: + # - no arbitrary lock is obtained; + # - all threads can read and work :) + # cons: + # - useless ton of objects (new dataset, new settings, new locks, and etc); + # - useless setting options assignment steps (self.dup + self.to_h + configure(to_h)) + dup.configure(configurations) + true + rescue Qonfig::ValidationError + false + end + # @return [void] # # @api public # @since 0.13.0 def validate! @@ -403,13 +435,15 @@ # @return [void] # # @api private # @since 0.2.0 + # @version 0.19.0 def build_settings - @settings = Qonfig::Settings::Builder.build(self) + @settings = Qonfig::Settings::Builder.build_definitions(self) validator.validate! + Qonfig::Settings::Builder.build_state(self) end # @return [void] # # @api private @@ -427,30 +461,19 @@ def apply_settings(settings_map = {}, &configurations) settings.__apply_values__(settings_map) yield(settings) if block_given? end - # @return [void] - # - # @api private - # @since 0.17.0 - def call_instance_management_commands - self.class.instance_commands.each do |instance_command| - instance_command.call(self, settings) - end - end - # @param settings_map [Hash] # @param configurations [Proc] # @return [void] # # @api private # @since 0.2.0 def load!(settings_map = {}, &configurations) build_validator build_settings - call_instance_management_commands apply_settings(settings_map, &configurations) end # @param file_path [String, Symbol] # @option format [String, Symbol] @@ -473,27 +496,32 @@ Qonfig::Commands::Instantiation::ValuesFile.new( file_path, caller_location, format: format, strict: strict, expose: expose ).call(self, settings) end - # @param instructions [Proc] - # @return [Object] + # @param instructions [Block] + # @return [Any] # # @api private # @since 0.2.0 def thread_safe_access(&instructions) @__lock__.thread_safe_access(&instructions) end - # @param instructions [Proc] - # @return [Object] + # @param instructions [Block] + # @return [Any] # # @api private # @since 0.2.0 def thread_safe_definition(&instructions) @__lock__.thread_safe_definition(&instructions) end + # @param instructions [Block] + # @return [Any] + # + # @api priavte + # @since 0.17.0 def with_arbitary_access(&instructions) @__lock__.with_arbitary_access(&instructions) end end