class Confection::Config
Config
encapsulates a single configuration entry as defined in a project’s configuration file.
Attributes
Most configuration are scripted. In thos cases the ‘@block` attributes holds the Proc instance, otherwise it is `nil`.
The name of the profile to which this configuration belongs.
The name of tool being configured.
Public Class Methods
Initialize Config
instance. Config
instances are per-configuration, which means they are associated with one and only one config entry.
# File lib/confection/config.rb, line 12 def initialize(tool, profile, context, value, &block) self.tool = tool self.profile = profile self.value = value self.block = block if block @context = context end
Public Instance Methods
The arity of the configuration procedure.
@return [Fixnum] number of arguments
# File lib/confection/config.rb, line 90 def arity @block ? @block.arity : 0 end
Set the configuration procedure.
@param [Proc] procedure
The configuration procedure.
# File lib/confection/config.rb, line 80 def block=(proc) @value = nil @block = proc.to_proc end
Call the procedure. Configuration procedures are evaluated in the scope of a per-configuration file context instance, which is extended by the {DSL} evaluation context.
# File lib/confection/config.rb, line 99 def call(*args) #@value || @block.call(*args) @value || @context.instance_exec(*args, &block) end
Copy the configuration with alterations.
@param [Hash] alt
Alternate values for configuration attributes.
@return [Config] copied config
# File lib/confection/config.rb, line 153 def copy(alt={}) copy = dup alt.each do |k,v| copy.__send__("#{k}=", v) end copy end
Change the profile name.
# File lib/confection/config.rb, line 43 def profile=(name) @profile = name.to_sym if name end
Return the value or procedure in the form of a Hash.
@return [Hash]
# File lib/confection/config.rb, line 125 def to_h (@value || HashBuilder.new(&@block)).to_h end
Convert the underlying procedure into an ‘instance_exec` procedure. This allows the procedure to be evaluated in any scope that it is be needed.
# File lib/confection/config.rb, line 109 def to_proc if value = @value lambda{ value } else block = @block lambda do |*args| instance_exec(*args, &block) end end end
Return the value or procedure in the form of a String.
@return [String]
# File lib/confection/config.rb, line 134 def to_s (@value || call).to_s end
Change the tool name. Note, this will rarely be used since, generally speaking, configurations tend to be very tool specific.
# File lib/confection/config.rb, line 31 def tool=(name) @tool = name.to_sym end
Some configuration are simple values. In those cases the ‘@value` attributes holds the object, otherwise it is `nil`.
# File lib/confection/config.rb, line 52 def value @value end
Set the configuration value.
@param [Object] value
The configuration value.
# File lib/confection/config.rb, line 62 def value=(value) @block = nil @value = value end