Module: Rib

Extended by:
Anchor::Imp, Byebug::Imp, Caller::Imp, Edit::Imp, LastValue::Imp
Defined in:
lib/rib/extra/byebug.rb,
lib/rib.rb,
lib/rib/api.rb,
lib/rib/shell.rb,
lib/rib/plugin.rb,
lib/rib/runner.rb,
lib/rib/version.rb,
lib/rib/app/auto.rb,
lib/rib/app/rack.rb,
lib/rib/app/rails.rb,
lib/rib/more/beep.rb,
lib/rib/more/edit.rb,
lib/rib/extra/hirb.rb,
lib/rib/more/color.rb,
lib/rib/more/anchor.rb,
lib/rib/more/caller.rb,
lib/rib/core/history.rb,
lib/rib/extra/paging.rb,
lib/rib/core/readline.rb,
lib/rib/core/multiline.rb,
lib/rib/core/completion.rb,
lib/rib/core/last_value.rb,
lib/rib/extra/autoindent.rb,
lib/rib/core/squeeze_history.rb,
lib/rib/core/strip_backtrace.rb,
lib/rib/more/multiline_history.rb,
lib/rib/more/bottomup_backtrace.rb,
lib/rib/more/multiline_history_file.rb

Overview

Defined Under Namespace

Modules: API, Anchor, Auto, Autoindent, Beep, BottomupBacktrace, Byebug, Caller, Color, Completion, Edit, Hirb, History, LastValue, Multiline, MultilineHistory, MultilineHistoryFile, Paging, Plugin, Rack, Rails, Readline, Runner, SqueezeHistory, StripBacktrace Classes: Shell

Constant Summary collapse

Skip =
Object.new
VERSION =
'1.6.1'
Blackhole =
Object.new

Class Method Summary collapse

Methods included from Edit::Imp

edit

Methods included from Anchor::Imp

anchor, stop_anchors

Methods included from Caller::Imp

caller, display_backtrace

Methods included from Byebug::Imp

byebug, finish, location, next, step

Methods included from LastValue::Imp

last_exception, last_value

Class Method Details

.abort(*words) ⇒ Object

Warn (print to $stderr, with colors in the future, maybe) something by the name of Rib and then exit(1).

Parameters:

  • words (Array[String])

    Words you want to warn before aborting.



128
129
130
131
# File 'lib/rib.rb', line 128

def abort *words
  warn(words)
  exit(1)
end

.configObject

All default Rib configs, would be passed to Shell.new in Rib.shell, but calling Shell.new directly won’t bring this in.



13
14
15
# File 'lib/rib.rb', line 13

def config
  @config ||= {:name => 'rib', :prefix => '.', :started_at => Time.now}
end

.config_pathObject

The config path where Rib tries to load upon Rib.shell. It is depending on where Rib.home was discovered if no specific config path was specified via -c or –config command



97
98
99
# File 'lib/rib.rb', line 97

def config_path
  @config_path ||= File.join(home, 'config.rb')
end

.config_path=(new_path) ⇒ Object



101
102
103
# File 'lib/rib.rb', line 101

def config_path= new_path
  @config_path = new_path
end

.disable_plugins(plugs = plugins) ⇒ Object

Convenient way to disable all plugins in the memory. This could also take a list of plugins and disable them.

Parameters:

  • plugs (Array) (defaults to: plugins)

    (Rib.plugins) Plugins which would be disabled.



66
67
68
# File 'lib/rib.rb', line 66

def disable_plugins plugs=plugins
  plugs.each(&:disable)
end

.enable_plugins(plugs = plugins) ⇒ Object

Convenient way to enable all plugins in the memory. This could also take a list of plugins and enable them.

Parameters:

  • plugs (Array) (defaults to: plugins)

    (Rib.plugins) Plugins which would be enabled.



75
76
77
# File 'lib/rib.rb', line 75

def enable_plugins plugs=plugins
  plugs.each(&:enable)
end

.homeObject

Rib.home is where Rib storing things. By default, it goes to ‘~/.rib’, or somewhere containing a ‘config.rb’ or ‘history.rb’ in the order of ‘./.rib’ (project specific config), or ‘~/.rib’ (home config), or ‘~/.config/rib’ (home config, residing in ~/.config)



33
34
35
36
37
38
39
# File 'lib/rib.rb', line 33

def home
  ENV['RIB_HOME'] ||= File.expand_path(
    ["#{config[:prefix]}/.rib", '~/.rib', '~/.config/rib'].find{ |path|
      File.exist?(File.expand_path(path))
    } || '~/.rib'
  )
end

.lastObject



24
25
26
# File 'lib/rib/core/readline.rb', line 24

def (::Readline::HISTORY).last
  self[-1]
end

.pluginsObject

All plugins which have been loaded into the memory regardless it’s enabled or not.



57
58
59
# File 'lib/rib.rb', line 57

def plugins
  Shell.ancestors.drop(1).select{ |a| a.singleton_class < Plugin }
end

.require_configObject

Load (actually require) the config file if it exists. This might emit warnings if there’s some error while loading it.



83
84
85
86
87
88
89
90
# File 'lib/rib.rb', line 83

def require_config
  result = require(config_path) if File.exist?(config_path)
  Rib.say("Config loaded from: #{config_path}") if $VERBOSE && result
  result
rescue StandardError, LoadError, SyntaxError => e
  Rib.warn("Error loading #{config_path}\n" \
           "  #{Rib::API.format_error(e)}")
end

.say(*words) ⇒ Object

Say (print to $stdout, with colors in the future, maybe) something by the name of Rib.

Parameters:

  • words (Array[String])

    Words you want to say.



110
111
112
# File 'lib/rib.rb', line 110

def say *words
  $stdout.puts(Rib.prepare(words))
end

.shellObject

Convenient shell accessor, which would just give you current last shell or create one and load the config file. If you need a clean shell which does not load config file, use Shell.new instead.



46
47
48
49
50
51
# File 'lib/rib.rb', line 46

def shell
  shells.last || begin
    require_config if config_path && config_path != Skip
    (shells << Shell.new(config)).last
  end
end

.shellsObject

All shells in the memory



18
19
20
# File 'lib/rib.rb', line 18

def shells
  @shells ||= []
end

.silenceObject



133
134
135
136
137
138
139
# File 'lib/rib.rb', line 133

def silence
  w, v = $-w, $VERBOSE
  $-w, $VERBOSE = false, false
  yield
ensure
  $-w, $VERBOSE = w, v
end

.varsObject

All shared variables for all shells



23
24
25
# File 'lib/rib.rb', line 23

def vars
  @vars   ||= {}
end

.warn(*words) ⇒ Object

Warn (print to $stderr, with colors in the future, maybe) something by the name of Rib.

Parameters:

  • words (Array[String])

    Words you want to warn.



119
120
121
# File 'lib/rib.rb', line 119

def warn *words
  $stderr.puts(Rib.prepare(words))
end