module Rib

from github.com/janlelis/ripl-multi_line

This is based on lib/byebug/processors/pry_processor.rb

Constants

Blackhole
Skip
VERSION

Private Class Methods

prepare(words) click to toggle source
# File lib/rib.rb, line 142
def self.prepare words
  name = config[:name]
  "#{name}: #{words.join("\n#{' '*(name.size+2)}")}"
end

Public Instance Methods

abort(*words) click to toggle source

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

@api public @param words [Array] Words you want to warn before aborting.

# File lib/rib.rb, line 128
def abort *words
  warn(words)
  exit(1)
end
config() click to toggle source

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

@api public

# File lib/rib.rb, line 13
def config
  @config ||= {:name => 'rib', :prefix => '.', :started_at => Time.now}
end
config_path() click to toggle source

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

@api public

# File lib/rib.rb, line 97
def config_path
  @config_path ||= File.join(home, 'config.rb')
end
config_path=(new_path) click to toggle source
# File lib/rib.rb, line 101
def config_path= new_path
  @config_path = new_path
end
disable_plugins(plugs=plugins) click to toggle source

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

@api public @param plugs [Array] (Rib.plugins) Plugins which would be disabled.

# File lib/rib.rb, line 66
def disable_plugins plugs=plugins
  plugs.each(&:disable)
end
enable_plugins(plugs=plugins) click to toggle source

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

@api public @param plugs [Array] (Rib.plugins) Plugins which would be enabled.

# File lib/rib.rb, line 75
def enable_plugins plugs=plugins
  plugs.each(&:enable)
end
home() click to toggle source

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)

@api public

# 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
plugins() click to toggle source

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

@api public

# File lib/rib.rb, line 57
def plugins
  Shell.ancestors.drop(1).select{ |a| a.singleton_class < Plugin }
end
require_config() click to toggle source

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

@api public

# 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) click to toggle source

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

@api public @param words [Array] Words you want to say.

# File lib/rib.rb, line 110
def say *words
  $stdout.puts(Rib.prepare(words))
end
shell() click to toggle source

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.

@api public

# 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
shells() click to toggle source

All shells in the memory

# File lib/rib.rb, line 18
def shells
  @shells ||= []
end
silence() { || ... } click to toggle source
# File lib/rib.rb, line 133
def silence
  w, v = $-w, $VERBOSE
  $-w, $VERBOSE = false, false
  yield
ensure
  $-w, $VERBOSE = w, v
end
vars() click to toggle source

All shared variables for all shells

# File lib/rib.rb, line 23
def vars
  @vars   ||= {}
end
warn(*words) click to toggle source

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

@api public @param words [Array] Words you want to warn.

# File lib/rib.rb, line 119
def warn *words
  $stderr.puts(Rib.prepare(words))
end