Module: Rib

Extended by:
Anchor::Imp, Edit::Imp
Defined in:
lib/rib.rb,
lib/rib/api.rb,
lib/rib/plugin.rb,
lib/rib/version.rb,
lib/rib/app/auto.rb,
lib/rib/app/rack.rb,
lib/rib/app/rails.rb,
lib/rib/app/ramaze.rb

Defined Under Namespace

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

Constant Summary collapse

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

Class Method Summary collapse

Methods included from Edit::Imp

edit

Methods included from Anchor::Imp

anchor

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.



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

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 ||= {:config => File.join(home, 'config.rb'), :name => 'rib'}
end

.config_pathObject

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



101
102
103
104
105
106
107
108
109
# File 'lib/rib.rb', line 101

def config_path
  return nil unless config[:config]
  path = File.expand_path(config[:config])
  if File.exist?(path)
    path
  else
    nil
  end
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.



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

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.



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

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
40
41
# File 'lib/rib.rb', line 33

def home
  ENV['RIB_HOME'] ||= begin
    ['./.rib', '~/.rib', '~/.config/rib'].find{ |path|
      p = File.expand_path(path)
      File.exist?(File.join(p, 'config.rb')) ||
      File.exist?(File.join(p, 'history.rb'))
    } || '~/.rib'
  end
end

.pluginsObject

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



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

def plugins
  Shell.ancestors[1..-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.



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

def require_config
  return unless config_path
  result = require(config_path)
  Rib.say("Config loaded from: #{config_path}") if $VERBOSE && result
  result
rescue StandardError, LoadError, SyntaxError => e
  Rib.warn("Error loading #{config[:config]}\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.



116
117
118
# File 'lib/rib.rb', line 116

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.



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

def shell
  shells.last || begin
    require_config if config_path
    (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



139
140
141
142
143
144
145
# File 'lib/rib.rb', line 139

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.



125
126
127
# File 'lib/rib.rb', line 125

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