class Loquacious::Undefined
Represents an undefined configuration value. An undefined value is assigned to each configuration propery by default. Any method can be invoked on an undefined value, and a warning message will be printed to the IO stream (defaulting to $stderr).
The purpose of this class is to provide the user with a helpful message that the configuration values they are trying to use have not been setup correctly.
Attributes
Public Class Methods
Creates a new undefined value returned from the lookup key in some configuration object. The key is used to alert the user where the undefined value came from.
# File lib/loquacious/undefined.rb, line 63 def initialize( key ) @key = Kernel.Array(key) end
Write a warning message to the Undefined class IO stream. By default, this IO stream is set to the Ruby $stderr output.
# File lib/loquacious/undefined.rb, line 42 def warn( key ) if @first_time @io.puts <<-__ --------------------------------------------------------------------------- The Loquacious configuration system has detected that one or moe settings have an undefined value. An attempt is being made to reference sub-properties of these undefined settings. Messages will follow containing information about the undefined properties. --------------------------------------------------------------------------- __ @first_time = false end @io.puts "Access to undefined value #{key.first.inspect}: #{key.join('.')}" end
Public Instance Methods
For every method invoked on an undefined object, generate a warning message describing the undefined value and the method that was called.
Returns a new undefined object with the most recent method included in the key name.
# File lib/loquacious/undefined.rb, line 84 def method_missing( method, *args, &block ) key = @key.dup << method.to_s Undefined.warn key return Undefined.new(key) end
An undefined value acts like a nil
in that it has no value of
its own. This method always returns true
.
# File lib/loquacious/undefined.rb, line 70 def nil?() true; end
We can respond to any method except :call. The call method is reserved for Procs and lambdas, and it is used internally by loquacious for lazy evaluation of configuration parameters.
# File lib/loquacious/undefined.rb, line 76 def respond_to_missing?( id, priv = false ) id != :call; end