Module: Brice

Extended by:
Brice
Includes:
DSL
Included in:
Brice
Defined in:
lib/brice/history.rb,
lib/brice.rb,
lib/brice/dsl.rb,
lib/brice/config.rb,
lib/brice/colours.rb,
lib/brice/version.rb,
lib/brice/shortcuts.rb

Overview

#

A component of brice, the extra cool IRb goodness donator #

#

Copyright (C) 2008-2014 Jens Wille #

#

Authors: #

Jens Wille <[email protected]>                                       #
                                                                        #

brice is free software: you can redistribute it and/or modify it under the # terms of the GNU Affero General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) # any later version. #

#

brice is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for # more details. #

#

You should have received a copy of the GNU Affero General Public License # along with brice. If not, see <www.gnu.org/licenses/>. #

#

++

Defined Under Namespace

Modules: Colours, DSL, Shortcuts, Version Classes: Config, History

Constant Summary collapse

RC_DIR =
__FILE__.sub(/\.rb\z/, '/rc')
BRICE_HOME =
File.join(ENV.user_home, '.brice')
VERSION =
Version.to_s
EDITORS =
#{ENV['VISUAL']}
#{ENV['EDITOR']}
/usr/bin/sensible-editor
/usr/bin/xdg-open
open
vi

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DSL

#brice, #brice_load, #brice_require, #brice_rescue, #brice_run_cmd, #irb_def

Instance Attribute Details

#configObject

Returns the value of attribute config


45
46
47
# File 'lib/brice.rb', line 45

def config
  @config
end

#irb_rcObject (readonly)

Returns the value of attribute irb_rc


45
46
47
# File 'lib/brice.rb', line 45

def irb_rc
  @irb_rc
end

#quietObject

Returns the value of attribute quiet


47
48
49
# File 'lib/brice.rb', line 47

def quiet
  @quiet
end

#verboseObject

Returns the value of attribute verbose


47
48
49
# File 'lib/brice.rb', line 47

def verbose
  @verbose
end

Instance Method Details

#custom_extensionsObject

call-seq:

Brice.custom_extensions => anArray

Get the custom extension files.


113
114
115
# File 'lib/brice.rb', line 113

def custom_extensions
  @custom_extensions ||= find_rc_files(BRICE_HOME)
end

#error(obj, met, err) ⇒ Object


126
127
128
# File 'lib/brice.rb', line 126

def error(obj, met, err)
  warn "Error in #{obj}##{met}: #{err.backtrace.first}: #{err} (#{err.class})"
end

#include?(package) ⇒ Boolean Also known as: have?

call-seq:

Brice.include?(package) => true or false
Brice.have?(package) => true or false

See whether package package is enabled/included.

Returns:

  • (Boolean)

93
94
95
# File 'lib/brice.rb', line 93

def include?(package)
  config.include?(package)
end

#init(options = {}) {|config| ... } ⇒ Object

call-seq:

Brice.init { |config| ... }
Brice.init(verbose: true) { |config| ... }

Initialize Brice and optionally configure any packages.

Yields:


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# 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) ⇒ Object

call-seq:

Brice.opt(opt, key, default = true) -> anObject

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


122
123
124
# 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) ⇒ Object

call-seq:

Brice.rc_files(include_custom_extensions = false) => anArray

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


104
105
106
107
# 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