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 83 def config=(config) 84 config.is_a?(Config) ? @config = config : 85 raise(TypeError, "Brice::Config expected, got #{config.class}") 86 end
custom_extensions → anArray
click to toggle source
Get the custom extension files.
# File lib/brice.rb 113 def custom_extensions 114 @custom_extensions ||= find_rc_files(BRICE_HOME) 115 end
error(obj, met, err)
click to toggle source
# File lib/brice.rb 126 def error(obj, met, err) 127 warn "Error in #{obj}##{met}: #{err.backtrace.first}: #{err} (#{err.class})" 128 end
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 93 def include?(package) 94 config.include?(package) 95 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 54 def init(options = {}) 55 @irb_rc = [] 56 57 options.each { |key, value| 58 respond_to?(set = "#{key}=") ? send(set, value) : 59 raise(ArgumentError, "illegal option: #{key}") 60 } 61 62 packages = rc_files(true).map { |rc| 63 File.basename(rc, '.rb').sub(/\A\d+_/, '') 64 }.reject { |rc| rc.end_with?('?') || rc.end_with?('_') } 65 66 warn "Default packages: #{packages.join(', ')}" if verbose 67 68 @config = Config.new(packages) 69 70 yield config if block_given? 71 72 load_rc_files(true) 73 finalize_irb_rc! 74 75 config 76 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 122 def opt(opt, key, default = true) 123 opt.is_a?(Hash) && opt.key?(key) ? opt[key] : default 124 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 104 def rc_files(include_custom_extensions = false) 105 @rc_files ||= find_rc_files 106 include_custom_extensions ? @rc_files + custom_extensions : @rc_files 107 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 171 def finalize_irb_rc! 172 IRB.conf[:IRB_RC] = lambda { |context| 173 irb_rc.each { |rc| rc[context] } 174 } unless irb_rc.empty? 175 end
find_rc_files(dir = ...) → anArray
click to toggle source
Find the actual extension files in dir
.
# File lib/brice.rb 163 def find_rc_files(dir = RC_DIR) 164 File.directory?(dir) ? Dir["#{dir}/**/*.rb"].sort : [] 165 end
load_custom_extensions → anArray
click to toggle source
Load the custom extension files.
# File lib/brice.rb 152 def load_custom_extensions 153 custom_extensions.each { |rc| 154 warn "Loading custom #{rc}..." if verbose 155 brice_load rc 156 } 157 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 137 def load_rc_files(include_custom_extensions = false) 138 Object.send(:include, DSL) 139 140 res = rc_files.each { |rc| 141 warn "Loading #{rc}..." if verbose 142 brice_load rc 143 } 144 145 include_custom_extensions ? res + load_custom_extensions : res 146 end