• Stars
    star
    226
  • Rank 176,514 (Top 4 %)
  • Language
    Ruby
  • License
    Apache License 2.0
  • Created over 13 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

Rib Pipeline status

by Lin Jen-Shin (godfat)

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) and JRuby.
  • All gem dependencies are optional, but it's highly recommended to use Rib with bond for tab completion.

INSTALLATION:

gem install rib

SYNOPSIS:

Screenshot

As an interactive shell

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

rib

As Rails console

rib rails

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

rib rails production --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.

For Rails Spring support, put this line in your ~/.spring.rb:

require 'rib/extra/spring'

As Rack console

rib rack

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

rib auto

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.

rib auto production --sandbox --debugger

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

rib all

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

rib all auto # 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.

My Personal ~/.config/rib/config

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:

require 'rib/core'
require 'rib/more/color'

You can also write your plugins there. Here's another example:

require 'rib/core'
require 'pp'
Rib.config[:prompt] = '$ '

module RibPP
  Rib::Shell.send(:include, self)

  def format_result result
    result_prompt + result.pretty_inspect
  end
end

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

Disable enabled plugins

While it's convenient to just require 'rib/all', you might not want to use all the plugins. No worries, you don't have to list everything in order to not use something. For example, you might not get used to bottomup_backtrace and don't want to use it. You could put this in your config:

require 'rib/all'

Rib::BottomupBacktrace.disable

This could disable bottomup_backtrace so you get regular top-down backtrace with all other plugins. This is particularly useful whenever there's a bug in one of the plugins, and you might need to disable some plugins in order to debug. You could always enable it again with:

Rib::BottomupBacktrace.enable

You could do this any time, in the config, or in the shell session. No need to restart anything, because it takes effect immediately.

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 ~/project auto

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

To check for more command line options, run rib -h:

Usage: rib [ruby OPTIONS] [rib OPTIONS] [rib COMMANDS]
ruby options:
  -e, --eval LINE        Evaluate a LINE of code
  -d, --debug            Set debugging flags (set $DEBUG to true)
  -w, --warn             Turn warnings on (set $-w and $VERBOSE to true)
  -I, --include PATH     Specify $LOAD_PATH (may be used more than once)
  -r, --require LIBRARY  Require the library, before executing your script
rib options:
  -c, --config FILE      Load config from FILE
  -p, --prefix PATH      Prefix to locate the app. Default to .
  -n, --no-config        Suppress loading ~/.config/rib/config.rb
  -h, --help             Print this message
  -v, --version          Print the version
rib commands:
  all                    Load all recommended plugins
  auto                   Run as Rails or Rack console (auto-detect)
  min                    Run the minimum essence
  rack                   Run as Rack console
  rails                  Run as Rails console

Basic configuration

Rib.config Functionality
ENV['RIB_HOME'] Specify where Rib should store config and history
Rib.config[:name] The name of this shell
Rib.config[:result_prompt] Default is "=>"
Rib.config[:prompt] Default is ">>"
Rib.config[:binding] Context, default: TOPLEVEL_BINDING
Rib.config[:exit] Commands to exit, default [nil] # control+d

Plugin specific configuration

Rib.config Functionality
Rib.config[:completion] Completion: Bond config
Rib.config[:history_file] Default is "~/.rib/history.rb"
Rib.config[:history_size] Default is 500
Rib.config[:color] A hash of Class => :color mapping
Rib.config[:autoindent_spaces] How to indent? Default is two spaces: ' '
Rib.config[:beep_threshold] When it should beep? Default is 5 seconds

List of core plugins

require 'rib/core' # You get all of the followings:
  • require 'rib/core/completion'

    Completion from bond.

  • require 'rib/core/history'

    Remember history in a history file.

  • require 'rib/core/strip_backtrace'

    Strip backtrace before Rib.

  • require 'rib/core/readline'

    Readline support.

  • require 'rib/core/multiline'

    You can interpret multiple lines.

  • require 'rib/core/squeeze_history'

    Remove duplicated input from history.

  • require 'rib/core/last_value'

    Save the last result in Rib.last_value and the last exception in Rib.last_exception.

List of more plugins

require 'rib/more' # You get all of the followings:
  • require 'rib/more/multiline_history_file'

    Not only readline could have multiline history, but also the history file.

  • require 'rib/more/bottomup_backtrace'

    Show backtrace bottom-up instead of the regular top-down.

  • require 'rib/more/color'

    Class based colorizing.

  • require 'rib/more/multiline_history'

    Make readline aware of multiline history.

  • require 'rib/more/beep'

    Print "\a" when the application was loaded and it's been too long. Configure the threshold via Rib.config[:beep_threshold].

  • require 'rib/more/anchor'

    See As a debugging/interacting tool.

  • require 'rib/more/caller'

    See Current call stack (backtrace, caller).

  • require 'rib/more/edit'

    See In place editing.

List of extra plugins

There's no require 'rib/extra' for extra plugins because they might not be doing what you would expect or want, or having an external dependency, or having conflicted semantics.

  • require 'rib/extra/autoindent' This plugin is depending on:

    1. readline_buffer
    2. readline plugin
    3. multiline plugin

    Which would autoindent your input.

  • require 'rib/extra/hirb' This plugin is depending on:

    1. hirb

    Which would print the result with hirb.

  • 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.

  • require 'rib/extra/spring' in your ~/.spring.rb for Rails Spring support.

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 config
require 'rib/more/anchor'
                     # If you enabled anchor in config, then needed not
Rib.anchor binding   # This would give you an interactive shell
                     # when your program has been executed here.
Rib.anchor 123       # 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_anchor do
  # Only `Rib.anchor` called in the block would launch a shell
end

Rib.anchor binding # 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/rack.rb and bin/rib-rack as a Rib App reference implementation, because it's very simple, simpler than rib-rails.

Other plugins and apps

  • rest-more rib rest-core Run as interactive rest-core client
  • rib-heroku rib heroku Run console on Heroku Cedar with your config

CONTRIBUTORS:

  • Andrew Liu (@eggegg)
  • ayaya (@ayamomiji)
  • Lin Jen-Shin (@godfat)
  • Mr. Big Cat (@miaout17)
  • @alpaca-tc
  • @bootleq
  • @lulalala
  • @MITSUBOSH
  • @tka

LICENSE:

Apache License 2.0 (Apache-2.0)

Copyright (c) 2011-2023, Lin Jen-Shin (godfat)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

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.

More Repositories

1

rest-graph

A lightweight Facebook Graph API client
Ruby
61
star
2

rest-core

Various rest-builder middleware for building REST clients.
Ruby
57
star
3

jellyfish

Pico web framework for building API-centric web applications
Ruby
52
star
4

muack

Muack -- Yet Another Mocking Library
Ruby
27
star
5

rest-more

Various REST clients such as Facebook and Twitter built with rest-core
Ruby
26
star
6

dm-is-reflective

DataMapper plugin that helps you manipulate an existing database.
Ruby
22
star
7

rubyqc

RubyQC -- A conceptual QuickCheck library for Ruby
Ruby
20
star
8

cubeat

a puyopuyo-like game (actually looks more like Panel de Pon, Meteos and Lumines).
C++
19
star
9

app-deploy

rake tasks for deployment
Ruby
11
star
10

slow-uploading

Demonstration for Slow uploading on Heroku Cedar stack with Unicorn
Ruby
10
star
11

rack-handlers

Unicorn family Rack handlers for you. Mostly for `rails s`
Ruby
8
star
12

gem-path

Find the path for a given gem or require path for editing or greping.
Ruby
8
star
13

ruby-server-exp

Ruby Application Server Experiments
Ruby
8
star
14

ripl-rc

ripl plugins collection, take you want, leave you don't.
Ruby
7
star
15

plruby

C
7
star
16

pork

Pork -- Simple and clean and modular testing library
Ruby
7
star
17

rack2

So this is an experiment and proof of concept to see if we could improve Rack without losing compatibility
Ruby
7
star
18

pagify

Pagination tools for Array(or custom class), DataMapper and ActiveRecord
Ruby
7
star
19

sandbox

my sandbox
Haskell
6
star
20

godfat.org

website for godfat.org (and other misc)
HTML
6
star
21

cht-phrases

Chinese phrases
Ruby
6
star
22

source-tools

source code tools collection
Ruby
5
star
23

logi

Highly customizable static blog/wiki generator
Ruby
5
star
24

dev-tool

clone this into ~/ without configuration?
Ruby
5
star
25

unigrep

Print Unicode information matching description. (grep Unicode data)
Ruby
5
star
26

promise_pool

promise_pool is a promise implementation backed by threads or threads pool.
Ruby
5
star
27

friendly_format

make user input be valid xhtml and format it with gsub("\n", "<br/>") etc.
Ruby
4
star
28

spellbook

this is an experiment to the models of spellbook
Scala
4
star
29

not-used-mogilefs-client

experiments from official mogilefs-client
Ruby
4
star
30

rack-rails-logger

Tell Rails to respect env['rack.logger']
Ruby
4
star
31

jin-rou

this is a web game based on 汝は人狼γͺγ‚Šγ‚„? built with ramaze and datamapper.
Ruby
4
star
32

godfat.org-rc

resources for godfat.org
HTML
4
star
33

thumbo

create thumbnails via RMagick
Ruby
4
star
34

rest-gw2

A very simple Guild Wars 2 API client built with rest-core.
Ruby
4
star
35

xmpp4r-robot

Simple XMPP client built upon xmpp4r. Intended for building simple robots.
Ruby
4
star
36

gw2-ludologists

A place to hold the information of members of characters of the Ludologists
AutoHotkey
4
star
37

sleepy_penguin

patches for sleepy_penguin -- http://bogomips.org/sleepy_penguin/
Ruby
3
star
38

gemgem

my gem tasks
Ruby
3
star
39

zbatery

patches for http://zbatery.bogomip.org/
Ruby
3
star
40

gem-bgrep

Can't find some codes from your app? gem-bgrep let you grep from your Gemfile.
Ruby
3
star
41

saya

Saya helps you post a post to different SNS simultaneously.
Ruby
3
star
42

cool.io-http

Simpler HTTP for cool.io
Ruby
3
star
43

request-replay

Replay the request via Rack env
Ruby
2
star
44

gem-eit

Edit the gem for a given name or edit the file for a given require path.
Ruby
2
star
45

gw-templates

my guild wars templates, mainly skill templates
Ruby
2
star
46

readline_buffer

Let you manipulate Readline.line_buffer
Ruby
2
star
47

struct_trans

Transform a struct with a schema to a hash, other struct, or more
Ruby
2
star
48

sync-defer

Synchronous deferred operations with fibers (coroutines)
Ruby
2
star
49

HurtGoblins.tmbundle

Strip Trailing Whites and Save in TextMate
2
star
50

dot-rc

my fish, gem, whatever configs...
CSS
2
star
51

bench

A Simple and Stupid Benchmark For Serving API
Ruby
2
star
52

gem-beit

Edit a gem for a given name from Gemfile.
Ruby
2
star
53

ludy

Aims to extend Ruby standard library, providing some useful tools that's not existed in the standard library, especially for functional programming.
Ruby
2
star
54

rest-builder

Modular Ruby clients interface for REST APIs.
Ruby
1
star
55

ludy-crypt

fork of http://crypt.rubyforge.org
Ruby
1
star
56

bullcow

http://en.wikipedia.org/wiki/Bulls_and_cows
Ruby
1
star
57

rainbows-emtp

EventMachineThreadPool model for Rainbows!
Ruby
1
star
58

poker-player-godfat

Haskell
1
star
59

jellyfish-contrib

Extra Jellyfish extensions.
JavaScript
1
star
60

gem-compact

Clean up gems for all the paths, including development dependencies.
Ruby
1
star
61

tidyup

! ( ) Tidy document s up your
Ruby
1
star
62

rest-api-cacher

A server that caches REST API result in MongoDB
Ruby
1
star
63

shere

Share the directory here with Nginx!
Ruby
1
star
64

heroku-buildpack-ruby-pure

Pure Ruby, No Rails
Ruby
1
star
65

not-used-rbx-include_remove

re-implementation of rbmodexcl in Rubinius
Ruby
1
star
66

rib-heroku

Run a Rib console on Heroku Cedar with your Rib config!
Ruby
1
star
67

fish_prompt-gitstatus

fish prompt with git status
Shell
1
star
68

id-img

generate identicon based on quilt, with nginx + rack
Ruby
1
star
69

avatarblock

as3 avatar block animation
ActionScript
1
star
70

minei

MineSweeper AI for PsMonkey's GWT MineSweeper
Scala
1
star
71

friendly_markdown

Simple markdown for user input, with auto-link, auto-linebreak, and sanitization.
Ruby
1
star
72

pork-rspec

RSpec compatibility layer for Pork
Ruby
1
star
73

nr

nr --net received-- The other side of nc
Ruby
1
star
74

gem-grep

grep the gem for a given name or grep the file for a given require path.
Ruby
1
star
75

gembox

minor gem collection
Ruby
1
star
76

fgbg

as3 foreground and background composer
ActionScript
1
star