lib/configurations/configuration.rb in configurations-1.3.0 vs lib/configurations/configuration.rb in configurations-1.3.1

- old
+ new

@@ -63,12 +63,14 @@ if _is_writer?(method) && @_writeable && _configurable?(property) _assign!(property, value) elsif !_is_writer?(method) && @_writeable || _configured?(method) @configuration[method] - else + elsif ::Kernel.respond_to?(method, true) ::Kernel.send(method, *args, &block) + else + super end end # Respond to missing according to the method_missing implementation # @@ -110,10 +112,15 @@ # def _arbitrarily_configurable? @configurable.nil? or @configurable.empty? end + # @return [Hash] the configurations configurable hash + def _configurable + @configurable + end + private # @param [Symbol] property The property to test for # @return [Boolean] whether the given property has been configured # @@ -135,23 +142,27 @@ return if _arbitrarily_configurable? @configurable.each do |k, assertion| if k.is_a?(::Hash) k.each do |property, nested| - @configuration[property] = Configuration.new(nil, _to_configurable_hash(nested, assertion)) + @configuration[property] = Configuration.new(nil, _configurable_hash(property, nested, assertion)) end end end end + # @param [Symbol, Hash, Array] property configurable properties, either single or nested # @param [Symbol, Hash, Array] value configurable properties, either single or nested - # @param [Class] type the type to assert, if any + # @param [Hash] assertions if any # @return a hash with configurable values pointing to their types # - def _to_configurable_hash(value, assertion) + def _configurable_hash(property, value, assertion) value = [value] unless value.is_a?(::Array) - ::Hash[value.zip([assertion].flatten*value.size)] + hash = ::Hash[value.zip([assertion].flatten*value.size)] + hash = @configuration[property]._configurable.merge(hash) if @configuration.has_key?(property) + + hash end # Assigns a value after running the assertions # @param [Symbol] property the property to type test # @param [Any] value the given value @@ -170,10 +181,10 @@ # def _assert_type!(property, value) return unless _evaluable?(property, :type) assertion = @configurable[property][:type] - ::Kernel.raise ConfigurationError, "Expected #{property} to be configured with #{expected_type}, but got #{value.class.inspect}", caller unless value.is_a?(assertion) + ::Kernel.raise ConfigurationError, "Expected #{property} to be configured with #{assertion}, but got #{value.class.inspect}", caller unless value.is_a?(assertion) end # Block assertion for configurable properties # @param [Symbol] property the property to type test # @param [Any] value the given value