lib/usable/mod_extender.rb in usable-1.3.1 vs lib/usable/mod_extender.rb in usable-1.4.0
- old
+ new
@@ -1,16 +1,19 @@
module Usable
class ModExtender
+ SPEC = :UsableSpec
+ CLASS_MODULE = :ClassMethods
+
attr_reader :name
attr_accessor :copy, :mod, :options, :unwanted
def initialize(mod, options = {})
@mod = mod
@options = options
@options[:method] ||= :include
if has_spec?
- @copy = mod.const_get(:UsableSpec)
+ @copy = mod.const_get SPEC
@name = "#{mod.name}UsableSpec"
else
@copy = mod
@name = mod.name
end
@@ -38,18 +41,24 @@
end
target.usable_config.modules << copy
target.send options[:method], copy
end
- # @description Sends the method to the target with the original module
+ # @description Includes or prepends the original module onto the target
def use_original!(target)
return unless has_spec?
target.usable_config.modules << mod
target.send options[:method], mod
end
+ # @description Extends the target with the module's ClassMethod mod
+ def use_class_methods!(target)
+ return unless mod.const_defined? CLASS_MODULE
+ target.extend mod.const_get CLASS_MODULE
+ end
+
def has_spec?
- mod.const_defined?(:UsableSpec)
+ mod.const_defined? SPEC
end
def mod_name
if name
name.split('::').last