Rib

LINKS:

DESCRIPTION:

Ruby-Interactive-ruBy -- Yet another interactive Ruby shell

Rib is based on the design of ripl and the work of ripl-rc, some of
the features are also inspired by pry. The aim of Rib is to be fully
featured and yet very easy to opt-out or opt-in other features. It shall
be simple, lightweight and modular so that everyone could customize Rib.

REQUIREMENTS:

Tested with MRI (official CRuby), Rubinius and JRuby.

All gem dependencies are optional, but it's highly recommended to use
Rib with bond for tab completion.

INSTALLATION:

geminstallrib

SYNOPSIS:

As an interactive shell

As IRB (reads ~/.rib/config.rb writes ~/.rib/history.rb)

rib

As Rails console

ribrails

You could also run in production and pass arguments normally as you'd do in
rails console or ./script/console

ribrailsproduction--sandbox--debugger

Note: You might need to add ruby-debug or ruby-debug19 to your Gemfile if
you're passing --debugger and using bundler together.

As a console for whichever the app in the current path
it should be (for now, it's either Rails, Ramaze or Rack)

ribauto

If you're trying to use rib auto for a Rails app, you could also pass
arguments as if you were using rib rails. rib auto is merely passing
arguments.

ribautoproduction--sandbox--debugger

As a fully featured interactive Ruby shell (as ripl-rc)

riball

As a fully featured app console (yes, some commands could be used together)

riballauto# or `rib auto all`, the order doesn't really matter

Customization

You can customize Rib's behaviour by setting a config file located at
$RIB_HOME/config.rb, or ./.rib/config.rb, or ~/.rib/config.rb, or
~/.config/rib/config.rb, searched by respected order. The default
would be ~/.rib/config.rb. Since it's merely a Ruby script which would
be loaded into memory before launching Rib shell session, You can put any
customization or monkey patch there. Personally, I use all plugins provided
by Rib.

As you can see, putting require 'rib/all' into config file is exactly the
same as running rib all without a config file. What rib all would do is
merely require the file, and that file is also merely requiring all plugins,
but without extra plugins, which you should enable them one by one. This
is because most extra plugins are depending on other gems, or hard to work
with other plugins, or having strong personal tastes, so you won't want to
enable them all. Suppose you only want to use the core plugins and color
plugin, you'll put this into your config file:

So that we override the original format_result to pretty_inspect the result.
You can also build your own gem and then simply require it in your config
file. To see a list of overridable API, please read api.rb

Rib home and history file

Rib home is used to store a config file and a history file, which is
searched in this order:

$RIB_HOME

./.rib

~/.rib

~/.config/rib

Rib would stop searching whenever the directory is found. If none could be
found, the default would be:

~/.rib

So the default history file would be located at ~/.rib/history.rb.

Project config and history

Since ./.rib would be searched before ~/.rib, you could create project
level config at the project directory, and the history would also be
separated from each other, located at the respected ./.rib/history.rb.

To do this, you don't really have to create a project config. Creating an
empty directory for Rib home at the project directory would also work.

Project directory and command line options

You could set the project directory by using -p, --prefix command line
option. So consider this:

cd~/project
rib auto

Would work the same as:

cd/tmp
rib -p ~/projectauto

And the project config and history would be located at ~/project/.rib.

Which introduces Rib.debug, which would do similar things as
Rib.anchor but only more powerful. However, this is not well
tested and might not work well. Please let me know if you have
any issue using it, thanks!

require 'rib/extra/paging' This plugin is depending on less and tput.

Which would pass the result to less (or $PAGER if set) if
the result string is longer than the screen.

As a debugging/interacting tool

Rib could be used as a kind of debugging tool which you can set break point
in the source program.

require'rib/config'# This would load your Rib configrequire'rib/more/anchor'# If you enabled anchor in config, then needed notRib.anchorbinding# This would give you an interactive shell# when your program has been executed here.Rib.anchor123# You can also anchor on an object.

But this might be called in a loop, you might only want to
enter the shell under certain circumstance, then you'll do:

require'rib/debug'Rib.enable_anchordo# Only `Rib.anchor` called in the block would launch a shellendRib.anchorbinding# No effect (no-op) outside the block

Anchor could also be nested. The level would be shown on the prompt,
starting from 1.

Current call stack (backtrace, caller)

Often time we would want to see current call stack whenever we're using
Rib.anchor. We could do that by simply using caller but it's barely
readable because it's just returning an array without any format and
it also contains backtrace from Rib itself. You could use pretty
formatting with Rib:

require'rib/more/caller'Rib.caller

It would use the same format for exception backtrace to show current
call stack for you. Colors, bottom up order, etc, if you're also using
the corresponding plugins.

Sometimes there are also too many stack frames which we don't care about.
In this case, we could pass arguments to Rib.caller in order to filter
against them. You could either pass:

A String represents the name of the gem you don't care

A Regexp which would be used to match against paths/methods you don't care

Examples:

require'rib/more/caller'Rib.caller'activesupport',/rspec/

To remove backtrace from gem activesupport and paths or methods containing
rspec as part of the name, like things for rspec or rspec-core and so on.
Note that if a method name also contains rspec then it would also be filtered.
Just keep that in mind when using regular expression.

Or if you don't care about any gems, only want to see application related
calls, then try to match against %r{/gems/} because gems are often stored
in a path containing /gems/:

Rib.caller%r{/gem/}

Happy debugging.

In place editing

Whenever you called:

require'rib/more/edit'Rib.edit

Rib would open an editor according to $EDITOR (ENV['EDITOR']) for you.
By default it would pick vim if no $EDITOR was set. After save and leave
the editor, Rib would evaluate what you had input. This also works inside
an anchor. To use it, require either rib/more/edit or rib/more or rib/all.

As a shell framework

The essence is:

require'rib'

All others are optional. The core plugins are lying in rib/core/*.rb, and
more plugins are lying in rib/more/*.rb. You can read rib/app/ramaze.rb
and bin/rib-ramaze as a Rib App reference implementation, because it's very
simple, simpler than rib-rails.

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.