module Brice

Constants

BRICE_HOME
EDITORS
RC_DIR
VERSION

Attributes

config[R]
irb_rc[R]
quiet[RW]
verbose[RW]

Public Instance Methods

config = config click to toggle source

Set config to config. Raises a TypeError if config is not a Brice::Config.

# File lib/brice.rb, line 83
def config=(config)
  config.is_a?(Config) ? @config = config :
    raise(TypeError, "Brice::Config expected, got #{config.class}")
end
custom_extensions → anArray click to toggle source

Get the custom extension files.

# File lib/brice.rb, line 113
def custom_extensions
  @custom_extensions ||= find_rc_files(BRICE_HOME)
end
have?(package)
Alias for: include?
include?(package) → true or false click to toggle source
have?(package) → true or false

See whether package package is enabled/included.

# File lib/brice.rb, line 93
def include?(package)
  config.include?(package)
end
Also aliased as: have?
init { |config| ... } click to toggle source
init(:verbose → true) { |config| ... }

Initialize Brice and optionally configure any packages.

# File lib/brice.rb, line 54
def init(options = {})
  @irb_rc = []

  options.each { |key, value|
    respond_to?(set = "#{key}=") ? send(set, value) :
      raise(ArgumentError, "illegal option: #{key}")
  }

  packages = rc_files(true).map { |rc|
    File.basename(rc, '.rb').sub(/\A\d+_/, '')
  }.reject { |rc| rc.end_with?('?') || rc.end_with?('_') }

  warn "Default packages: #{packages.join(', ')}" if verbose

  @config = Config.new(packages)

  yield config if block_given?

  load_rc_files(true)
  finalize_irb_rc!

  config
end
opt(opt, key, default = true) → anObject click to toggle source

Returns the value of opt at key if present, or default otherwise.

# File lib/brice.rb, line 122
def opt(opt, key, default = true)
  opt.is_a?(Hash) && opt.key?(key) ? opt[key] : default
end
rc_files(include_custom_extensions = false) → anArray click to toggle source

Get the extension files, optionally including custom extensions if include_custom_extensions is true.

# File lib/brice.rb, line 104
def rc_files(include_custom_extensions = false)
  @rc_files ||= find_rc_files
  include_custom_extensions ? @rc_files + custom_extensions : @rc_files
end

Private Instance Methods

finalize_irb_rc! → aProc click to toggle source

Generate proc for IRB_RC from all added procs.

# File lib/brice.rb, line 167
def finalize_irb_rc!
  IRB.conf[:IRB_RC] = lambda { |context|
    irb_rc.each { |rc| rc[context] }
  } unless irb_rc.empty?
end
find_rc_files(dir = ...) → anArray click to toggle source

Find the actual extension files in dir.

# File lib/brice.rb, line 159
def find_rc_files(dir = RC_DIR)
  File.directory?(dir) ? Dir["#{dir}/**/*.rb"].sort : []
end
load_custom_extensions → anArray click to toggle source

Load the custom extension files.

# File lib/brice.rb, line 148
def load_custom_extensions
  custom_extensions.each { |rc|
    warn "Loading custom #{rc}..." if verbose
    brice_load rc
  }
end
load_rc_files(include_custom_extensions = false) → anArray click to toggle source

Load the extension files, optionally including custom extensions if include_custom_extensions is true.

# File lib/brice.rb, line 133
def load_rc_files(include_custom_extensions = false)
  Object.send(:include, DSL)

  res = rc_files.each { |rc|
    warn "Loading #{rc}..." if verbose
    brice_load rc
  }

  include_custom_extensions ? res + load_custom_extensions : res
end