Sha256: 0880f46ef4d573b9ab6e40dfabcfd0734915870017abaf8b26e84e984a0dfc68
Contents?: true
Size: 1.71 KB
Versions: 7
Compression:
Stored size: 1.71 KB
Contents
require 'rib' module Rib::Anchor extend Rib::Plugin Shell.use(self) # --------------- Rib API --------------- def loop_eval str return super if Rib::Anchor.disabled? if eval_binding.kind_of?(Binding) super else eval_binding.instance_eval(str, "(#{name})", line) end end def prompt return super if Rib::Anchor.disabled? return super unless config[:prompt_anchor] level = "(#{Rib.shells.size - 1})" if Rib.const_defined?(:Color) && kind_of?(Rib::Color) && Rib::Color.enabled? "#{format_color(eval_binding, prompt_anchor)}#{level}#{super}" else "#{prompt_anchor}#{level}#{super}" end end # --------------- Plugin API --------------- # override Underscore#bound_object def bound_object return super if Rib::Anchor.disabled? return super if eval_binding.kind_of?(Binding) eval_binding end private def prompt_anchor @prompt_anchor ||= if eval_binding.kind_of?(Binding) eval_binding.eval('self', __FILE__, __LINE__) else eval_binding end.inspect[0..9] end module Imp def anchor obj_or_binding, opts={} return if Rib::Anchor.disabled? if Rib.shell.running? Rib.shells << Rib::Shell.new( Rib.shell.config.merge( :binding => obj_or_binding, :prompt_anchor => true ). merge(opts)) else Rib.shell.config.merge!(:binding => obj_or_binding, :prompt_anchor => true ). merge!(opts) end Rib.shell.loop Rib::Skip ensure Rib.shells.pop end end Rib.extend(Imp) end
Version data entries
7 entries across 7 versions & 1 rubygems