lib/rib/plugin.rb in rib-1.0.5 vs lib/rib/plugin.rb in rib-1.1.0
- old
+ new
@@ -1,32 +1,34 @@
module Rib; end
module Rib::Plugin
- def self.included mod
- mod.send(:include, Rib)
+ attr_accessor :disabled
- class << mod
- attr_accessor :disabled
+ def enable
+ self.disabled = false
+ if block_given? then yield else enabled? end
+ ensure
+ self.disabled = true if block_given?
+ end
- def enable
- self.disabled = false
- if block_given? then yield else enabled? end
- end
+ def disable
+ self.disabled = true
+ if block_given? then yield else enabled? end
+ ensure
+ self.disabled = false if block_given?
+ end
- def disable
- self.disabled = true
- if block_given? then yield else enabled? end
- end
+ def enabled?
+ !disabled
+ end
- def enabled?
- !disabled
- end
+ def disabled?
+ !!disabled
+ end
- def disabled?
- !!disabled
- end
- end
+ def self.extended mod
+ mod.send(:include, Rib)
snake_name = mod.name.sub(/(\w+::)+?(\w+)$/, '\2').
gsub(/([A-Z][a-z]*)/, '\\1_').downcase[0..-2]
code = (%w[enable disable].map{ |meth|
@@ -41,14 +43,8 @@
#{mod.name}.#{meth}(&block)
end
RUBY
}).join("\n")
- meta_rib = if respond_to?(:singleton_class)
- Rib.singleton_class
- else
- class << Rib; self; end
- end
-
- meta_rib.module_eval(code, __FILE__, __LINE__)
+ Rib.singleton_class.module_eval(code, __FILE__, __LINE__)
end
end