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.3'
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.



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

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.



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

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



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

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

.config_path=(new_path) ⇒ Object



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

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.



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

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.



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

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)



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

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



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

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

.pluginsObject

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



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

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

.prepare(words) ⇒ Object



143
144
145
146
# File 'lib/rib.rb', line 143

def self.prepare words
  name = config[:name]
  "#{name}: #{words.join("\n#{' '*(name.size+2)}")}"
end

.require_configObject

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



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

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.



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

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.



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

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



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

def shells
  @shells ||= []
end

.silenceObject



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

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

.varsObject

All shared variables for all shells



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

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.



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

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