lib/usable.rb in usable-2.2.0 vs lib/usable.rb in usable-2.2.1

- old
+ new

@@ -4,22 +4,24 @@ require 'usable/mod_extender' require 'usable/config' module Usable - # @description Define an instance level version of +usables+ def self.extended(base) base.class_eval do - def usables - self.class.usables - end - def usable_method(method_name) self.class.usable_method(self, method_name) end end - unless base.is_a? Class + if base.is_a? Class + # Define an instance level version of +usables+ + base.class_eval do + def usables + self.class.usables + end + end + else base.instance_eval do def config(&block) usables(&block) end unless defined? config end @@ -51,11 +53,11 @@ # @param [Hash] options Customize the extension of the module as well as define config settings on the target # @option [Array,Symbol] :only Limit which methods are copied from the module # @option [String,Symbol] :method (:include) The method to use for including the module # @return self def usable(mod, options = {}, &block) - usable_options = { only: options.delete(:only), method: options.delete(:method) } + ModExtender.new(mod, only: options.delete(:only), method: options.delete(:method)).call self # Define settings on @usables and on the scoped @usables scope = Config.new if mod.name scope_name = mod.name.split('::').last.gsub(/\B([A-Z])([a-z_0-9])/, '_\1\2').downcase usables[scope_name] = scope @@ -75,10 +77,9 @@ send :include, mod.const_get(:InstanceMethods) end if mod.const_defined?(:ClassMethods) send :extend, mod.const_get(:ClassMethods) end - ModExtender.new(mod, usable_options).call self self end # @return [Method] bound to the given -context- def usable_method(context, method_name)