class Courtier::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`.
Public Class Methods
Initialize Config
instance. Config
instances are per-configuration, which means they are associated with one and only one config entry.
@param [#to_sym] tool
The tool's name.
@param [#to_sym,nil] profile
Profile name, or +nil+.
@param [Hash] properties
Any additional properties associated with the config entry.
# File lib/courtier/config.rb, line 21 def initialize(tool, properties={}, &block) @property = {:profile=>'default'} @property[:command] = tool.to_s @property[:feature] = tool.to_s @block = block properties.each do |k, v| property(k,v) end end
Public Instance Methods
Does the configuration apply?
@return [Boolean]
# File lib/courtier/config.rb, line 241 def apply?() return false unless command? if command return false unless profile? if profile return true end
The arity of the configuration procedure.
@return [Fixnum] number of arguments
# File lib/courtier/config.rb, line 110 def arity @block ? @block.arity : 0 end
Call the configuration procedure.
# File lib/courtier/config.rb, line 128 def call(*args) block.call(*args) if block end
The name of command being configured.
# File lib/courtier/config.rb, line 60 def command @property[:command] end
Does the given ‘command` match the config’s command?
@return [Boolean]
# File lib/courtier/config.rb, line 203 def command?(command=Courtier.current_command) self.command == command.to_s end
Copy the configuration with alterations.
@param [Hash] alt
Alternate values for configuration attributes.
@return [Config] copied config
# File lib/courtier/config.rb, line 156 def copy(alt={}) tool = @property[:feature] || @property[:command] copy = self.class.new(tool, @property.dup, &@block) alt.each do |k,v| copy.property(k, v) end copy end
The feature being configured.
# File lib/courtier/config.rb, line 53 def feature @property[:feature] end
Does the given ‘feature` match the config’s feature?
@return [Boolean]
# File lib/courtier/config.rb, line 194 def feature?(feature=Courtier.current_feature) self.feature == feature.to_s end
The library from which this configuration derives. This is a shortcut for ‘property(:from)`.
# File lib/courtier/config.rb, line 80 def from @property[:from] end
Match config against tool and/or profile names.
@return [Boolean]
# File lib/courtier/config.rb, line 170 def match?(*args) props = Hash === args.last ? args.pop : {} if tool = args.shift props[:command] = tool.to_s props[:feature] = tool.to_s end if props[:profile] props[:profile] = (props[:profile] || :default).to_s end props.each do |k,v| return false unless property(k) == v end return true end
# File lib/courtier/config.rb, line 87 def onload? @property[:onload] end
The name of the profile to which this configuration belongs.
# File lib/courtier/config.rb, line 72 def profile @property[:profile] end
Does the given ‘profile` match the config’s profile?
@return [Boolean]
# File lib/courtier/config.rb, line 212 def profile?(profile=Courtier.current_profile) self.profile == (profile || :default).to_s end
Get/set property.
# File lib/courtier/config.rb, line 37 def property(name, value=ArgumentError) name = name.to_sym return @property[name] if value == ArgumentError case name when :feature, :command, :profile @property[name] = value.to_s else @property[name] = value end end
Require the feature.
# File lib/courtier/config.rb, line 117 def require_feature begin require feature rescue LoadError #warn "No such feature -- `#{feature}'" end end
Returns underlying block.
# File lib/courtier/config.rb, line 135 def to_proc block end