class Brice::Config

Exclude unwanted packages:

config.exclude 'foo', 'bar'
Brice.config -= %w[quix quux]

Include non-default packages:

config.include 'foo', 'bar'
Brice.config += %w[quix quux]

Configure individual packages (depends on package):

# set property
config.foo.bar = 'baz'

# set multiple properties
config.foo = %w[bar baz]
# which is equivalent to:
config.foo.bar = true
config.foo.baz = true

# reset package configuration
config.foo!

# see whether package is enabled/included
config.foo?

Attributes

packages[R]

Public Class Methods

new(packages = []) click to toggle source
# File lib/brice/config.rb, line 62
def initialize(packages = [])
  @packages = Hash.new { |h, k| h[k] = PackageConfig.new }
  self.include(*packages)
end

Public Instance Methods

%(*packages)
Alias for: only
+(*packages)
Alias for: include
-(*packages)
Alias for: exclude
config[package] click to toggle source

Accessor for package package.

# File lib/brice/config.rb, line 71
def [](package)
  packages[package.to_s]
end
clear click to toggle source

Clear all packages.

# File lib/brice/config.rb, line 116
def clear
  packages.clear
end
exclude(*packages) click to toggle source
config -= packages

Disable/exclude packages packages.

# File lib/brice/config.rb, line 92
def exclude(*packages)
  packages.each { |package| self.packages.delete(package.to_s) }
  self
end
Also aliased as: -
have?(package)
Alias for: include?
include(*packages) click to toggle source
config += packages

Enable/include packages packages.

# File lib/brice/config.rb, line 80
def include(*packages)
  packages.each { |package| self[package] }
  self
end
Also aliased as: +
include?(package) → true or false click to toggle source
have?(package) → true or false

See whether package package is enabled/included.

# File lib/brice/config.rb, line 125
def include?(package)
  packages.include?(package.to_s)
end
Also aliased as: have?
package # package configuration click to toggle source
package = 'foo' # equivalent to: config.package.foo = true
package = %w[foo bar] # see above, multiple
package! # reset package configuration
package? # see whether package is enabled/included

Convenience accessors to individual package configurations.

# File lib/brice/config.rb, line 139
def method_missing(method, *args)
  package, punctuation = method.to_s.sub(/([=!?])?\z/, ''), $1

  assignment = punctuation == '='

  unless assignment || args.empty?
    raise ArgumentError, "wrong number of arguments (#{args.size} for 0)"
  end

  case punctuation
    when '=', '!'
      config = packages[package] = PackageConfig.new

      assignment ? Array(args.first).each { |arg|
        config.send("#{arg}=", true)
      } : config
    when '?'
      include?(package)
    else
      self[package]
  end
end
only(*packages) click to toggle source
config %= packages

Enable/include only packages packages, disable/exclude everything else.

# File lib/brice/config.rb, line 105
def only(*packages)
  clear
  self.include(*packages)
end
Also aliased as: %