lib/configurations/arbitrary.rb in configurations-2.2.0 vs lib/configurations/arbitrary.rb in configurations-2.2.1
- old
+ new
@@ -28,11 +28,13 @@
if __respond_to_writer?(method)
__assign!(method.to_s[0..-2].to_sym, args.first)
elsif __respond_to_method_for_write?(method)
@data[method]
elsif __respond_to_method_for_read?(method, *args, &block)
- @data.fetch(method, &__not_configured_callback_for__(method))
+ @data.fetch(method) do
+ @not_configured_blocks.evaluate!(@path.add(method), method)
+ end
else
super
end
end
@@ -52,33 +54,26 @@
# Unassignable values are ignored
# @raise [ArgumentError] unless used in writeable state
# (in configure block)
#
def from_h(h)
- unless @__writeable__
+ unless @writeable
fail ::ArgumentError, 'can not dynamically assign values from a hash'
end
super
end
- # @param [Symbol] property The property to test for configurability
- # @return [Boolean] whether the given property is configurable
- #
- def __configurable?(_property)
- true
- end
-
# Set the configuration to writeable or read only. Access to writer methods
# is only allowed within the configure block, this method is used to invoke
# writeability for subconfigurations.
# @param [Boolean] data true if the configuration should be writeable,
# false otherwise
#
def __writeable__=(data)
- @__writeable__ = data
- return if @data.nil?
+ @writeable = data
+ return unless defined?(@data) && @data
@data.each do |_k, v|
v.__writeable__ = data if v.is_a?(__class__)
end
end
@@ -102,11 +97,11 @@
# @param [Symbol] method the method to test for
# @return [Boolean] whether the configuration responds to the given
# property as a method during writeable state
#
def __respond_to_method_for_write?(method)
- !__is_writer?(method) && @__writeable__ && @data[method].is_a?(__class__)
+ !__is_writer?(method) && @writeable && @data[method].is_a?(__class__)
end
# @param [Symbol] method the method to test for
# @return [Boolean] whether the configuration responds to the
# given property
@@ -118,9 +113,9 @@
# @param [Symbol] method the method to test for
# @return [Boolean] whether the method is a writer and is used in writeable
# state
#
def __respond_to_writer?(method)
- @__writeable__ && __is_writer?(method)
+ @writeable && __is_writer?(method)
end
end
end