class Courtier::Config

Config encapsulates a single configuration entry as defined in a project’s configuration file.

Attributes

block[R]

Most configuration are scripted. In thos cases the ‘@block` attributes holds the Proc instance, otherwise it is `nil`.

Public Class Methods

new(tool, properties={}, &block) click to toggle source

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

apply?() click to toggle source

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
arity() click to toggle source

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(*args) click to toggle source

Call the configuration procedure.

# File lib/courtier/config.rb, line 128
def call(*args)
  block.call(*args) if block
end
command() click to toggle source

The name of command being configured.

# File lib/courtier/config.rb, line 60
def command
  @property[:command]
end
Also aliased as: tool
command?(command=Courtier.current_command) click to toggle source

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(alt={}) click to toggle source

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
feature() click to toggle source

The feature being configured.

# File lib/courtier/config.rb, line 53
def feature
  @property[:feature]
end
feature?(feature=Courtier.current_feature) click to toggle source

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
from() click to toggle source

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?(*args) click to toggle source

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
onload?() click to toggle source
# File lib/courtier/config.rb, line 87
def onload?
  @property[:onload]
end
profile() click to toggle source

The name of the profile to which this configuration belongs.

# File lib/courtier/config.rb, line 72
def profile
  @property[:profile]
end
profile?(profile=Courtier.current_profile) click to toggle source

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
property(name, value=ArgumentError) click to toggle source

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_feature() click to toggle source

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
to_proc() click to toggle source

Returns underlying block.

# File lib/courtier/config.rb, line 135
def to_proc
  block
end
tool()

@todo Deprecate?

Alias for: command