Module: Rib::Plugin
- Included in:
- Anchor, Autoindent, Beep, BottomupBacktrace, Byebug, Caller, Color, Completion, Edit, Hirb, History, LastValue, Multiline, MultilineHistory, MultilineHistoryFile, Paging, Readline, SqueezeHistory, StripBacktrace
- Defined in:
- lib/rib/plugin.rb
Instance Attribute Summary collapse
-
#disabled ⇒ Object
Returns the value of attribute disabled.
Class Method Summary collapse
Instance Method Summary collapse
-
#const_missing(mod) ⇒ Object
Backward compatibility.
- #disable ⇒ Object
- #disabled? ⇒ Boolean
- #enable ⇒ Object
- #enabled? ⇒ Boolean
Instance Attribute Details
#disabled ⇒ Object
Returns the value of attribute disabled.
3 4 5 |
# File 'lib/rib/plugin.rb', line 3 def disabled @disabled end |
Class Method Details
.extended(mod) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rib/plugin.rb', line 39 def self.extended mod return unless mod.name snake_name = mod.name.sub(/(\w+::)+?(\w+)$/, '\2'). gsub(/([A-Z][a-z]*)/, '\\1_').downcase[0..-2] code = (%w[enable disable].map{ |meth| <<-RUBY def #{meth}_#{snake_name} &block #{mod.name}.#{meth}(&block) end RUBY } + %w[enabled? disabled?].map{ |meth| <<-RUBY def #{snake_name}_#{meth} &block #{mod.name}.#{meth}(&block) end RUBY }).join("\n") Rib.singleton_class.module_eval(code, __FILE__, __LINE__) end |
Instance Method Details
#const_missing(mod) ⇒ Object
Backward compatibility
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rib/plugin.rb', line 28 def const_missing mod if Rib.const_defined?(mod) Rib.warn("Using #{mod} is deprecated, please change to Rib::#{mod}", "This compatibility layer would be removed in Rib 1.6+", "Called: #{caller.first}") Rib.const_get(mod) else super end end |
#disable ⇒ Object
12 13 14 15 16 17 |
# File 'lib/rib/plugin.rb', line 12 def disable self.disabled = true if block_given? then yield else enabled? end ensure self.disabled = false if block_given? end |
#disabled? ⇒ Boolean
23 24 25 |
# File 'lib/rib/plugin.rb', line 23 def disabled? !!disabled end |
#enable ⇒ Object
5 6 7 8 9 10 |
# File 'lib/rib/plugin.rb', line 5 def enable self.disabled = false if block_given? then yield else enabled? end ensure self.disabled = true if block_given? end |
#enabled? ⇒ Boolean
19 20 21 |
# File 'lib/rib/plugin.rb', line 19 def enabled? !disabled end |